Ku Nole Ku Nole - 1 month ago 6
Javascript Question

React Router + ReactJS: How to pass props via <Link/>?

I want to pass params from route Home to the route Table I navigate to using , and use the params in the Table route.

I tried the following, and checked this.props in Table, but only seeing proto: Object in

this.props.routeParams
. What am I doing wrong?

Router set up:

<Router history={hashHistory}>
<Route
component={Start}
path='/'
>
<IndexRoute component={Home}/>
<Route
component={Table}
path='Details'
/>
</Route>
</Router>


Tried the following (
userInfo
is an object):

<Link to={{pathname: '/table', query: userInfo}}>
<div>
Pass userInfo Object to Table Route
</div>
</Link>


Thank you and will be sure to accept answer.

Answer

Home :

<Link to="/table" state={{query: userInfo}}>
  <div>
     Pass userInfo Object to Table Route
  </div>
</Link>

Table :

componentDidMount () { 
   console.log(
     this.props.location.state 
  ) //{query: userInfo}
}
Comments