Answer the question
In order to leave comments, you need to log in
React js. How to get a parameter from a nested route?
There is react-router (react-router 2.*):
<Router history={hashHistory}>
<Route path="/" component={App}>
<Route path="list/:id" component={List} />
<Route path="another/:id" component={Another} />
</Route>
</Router>
<div className="wrapper">
<MenuList />
{this.props.children}
</div>
Answer the question
In order to leave comments, you need to log in
Add a getId() function to the List component, which will return this.props.params.id
. And in the App, you can add a function that will return all ids of all children.
A reference to the function can be passed as a parameter when creating the MenuList component.
And the MenuList will call it on rendering and parse which items to make active and which not.
Alternatively, you can make a store (see Flux ) that will contain data about the rendered components. And then everyone (App, MenuList, List) will communicate only with this store.
If I understand part of your question correctly, in App you can get the :id of child components like this:
if (this.props.children)
console.log(this.props.children.props.params.id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question