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.

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.