1

Assuming I have a code like this:

   <Router history={history}>
     <Route path="/users/(:userId)" component={UserContainer}>
       <Route path="profile" component={UserProfileContainer} />
       <Route path="stats" component={UserStatsContainer}>
       <IndexRoute component={UserDashboard} />
     </Route>
   </Router>

In the UserContainer, I have something like this:

const {userId} = this.props.params;
return (
  <div>
    {this.props.children}
  </div>
);

How can I pass the userId to the child components (UserProfileContainer, UserStatsContainer, etc) defined in the router config?

Those components need to know the current userId as well.

Thanks.

Weihong Diao
  • 718
  • 6
  • 12

1 Answers1

2

u can get it just like u did in 'UserContainer' : 'const {userId} = this.props.params;'....... : )

Gemini Wei
  • 36
  • 4
  • Do you mean I can use the exactly the same way to get the parameter value in the child component (UserProfileContainer), as what I did in the UserContainer? – Weihong Diao Oct 15 '15 at 09:39