1

I have to pass a data from one screen to another in reactjs. And to display the data on the receiver side.

I used a router to navigate between screen also passed data but couldn't display the received data. The below code is where the data I passed.

<div onClick={() => this.props.history.push('/About', 
{ id:"2" })} class="col-sm-3 anchor">  

<img className="cat-img" src=""/>

<h3 className="text-center">name</h3>
</div>

I am trying to get the props using this following code in screen 2

{this.props.history.id}
M Reza
  • 18,350
  • 14
  • 66
  • 71
Ramesh KR
  • 143
  • 1
  • 9

1 Answers1

0

In order to access the routing props in the other screen you have to use:

this.props.match.params.id

But first, of course, you should a proper component in your routing file with a path like:

<Route path="/your/path/:id" ... />
0xc14m1z
  • 3,675
  • 1
  • 14
  • 23
  • sorry, it's not showing the params. I'm trying to pass from one screen to another screen... It's from app.js to about.js. pls, help me out. – Ramesh KR Jan 19 '19 at 11:18
  • Then add your router configuration, app.js and about.js to your answer please. – 0xc14m1z Jan 19 '19 at 11:26