0

I have multiple routes in my webapp like normal. I have a few questions regarding the best ways to pass information down the chain since I can't really find a solid answer:

  1. How would I pass what the current route is down to the children components? I have a global component that is used across every page of my webapp. On one of the page's, the content has to be different. The only way I can do this is by knowing what page is being served. Or am I thinking of this incorrectly and should just parse window.location on componentDidMount() to get everything I need?

  2. This is kind of tied in to the above point. Let's say I have a parameterized route (/test/:id), and one of its child components needs to perform some ajax request when a button is clicked, and needs to pass in the :id to the endpoint. How would I be able to get this done?

Maybe I have to pass things down as properties starting from the route level all the way down?

I'm just trying to figure out what the best option is.

Thanks!

Smbobeast
  • 17
  • 5
  • This might help. You can use action in the universal router. https://github.com/kriasoft/universal-router/blob/master/docs/api.md – sww314 Feb 23 '17 at 14:32

1 Answers1

0

You cant pass properties all the way down or you can put properties in store and connect your components to the store. If you want to go the store way you can try the redux branch of react-starter-kit. This is what I've done. On root paths I will put my parameters into store and all other children can read them. Here is the redux implementation of react-starter-kit:

https://github.com/kriasoft/react-starter-kit/tree/feature/redux

Iman Mohamadi
  • 6,552
  • 3
  • 34
  • 33