How to transfer the details in response to the v4 router?

I need to transfer some data in the Link component of react router v4 , but I cannot find a way to do this.

Basically, I have some links that are dynamically generated. I linked these links to the Link component as follows. After clicking one of these links, the user is redirected to the new component. I want to pass some data to this new component so that I can display it.

 <Link to="dynamic link here">some text</Link> 

Is there any <Link to="path" data="data here">some text</Link> react router v4 in react router v4 ? It seems I can not find it on the documentation page.

+5
source share
1 answer

You can pass the object as to prop and specify state . See docs .

 <Link to={{ pathname: '/courses', state: { fromDashboard: true } }}> Courses </Link> 

You can then capture this state on a new route from this.props.location.state

+16
source

Source: https://habr.com/ru/post/1265687/


All Articles