How can I pass the information displayed by that particular <div/>
so that I can display that particular information in the route that I navigated to as well?
Thank you and will accept/upvote the answer
How can I pass the information displayed by that particular <div/>
so that I can display that particular information in the route that I navigated to as well?
Thank you and will accept/upvote the answer
I am not entirely sure I understand your exact problem, but I assume you just want to pass params to the route you navigate to using <Link>
Take a look at this: https://github.com/ReactTraining/react-router/blob/master/docs/API.md#link
In the documentation, about to
prop it says:
A location descriptor. Usually this is a string or an object [...]
If it's an object it can have four keys:
pathname
: A string representing the path to link to.
query
: An object of key:value pairs to be stringified. [...]
And the example of this:
<Link to={{ pathname: '/hello', query: { name: 'ryan' } }}>
Hello
</Link>
So your case might look like:
render() {
var profile = this.props.profile;
var query = {
firstName: profile.firstName,
lastName: profile.lastName
};
return (
<Link to={{ pathname: '/details', query: query }}>
<div>
<div>
{profile.firstName}
</div>
<div>
{profile.lastName}
</div>
</div>
</Link>
)
}
Your details page should then be able to access the params from: this.props.routeParams
object which will have your query params that you passed in
Maybe you can try something like this :
Your router :
<Router history={hashHistory}>
<Route component={Root} path='/'>
<IndexRoute component={Profile}/>
<Route component={Details} path='details/:id'/>
</Route>
</Router>
Then you can create your link like
<Link to="details/profile">Profile</Link>
And then inside details you can check for passed id with
this.props.params.id
and then depending on that id you can show your data.