0

I am using history.push in React in a specific page inside a function so that once the button is clicked it pushes to a specific page

someFunction (paramToPass) { this.props.history.push('/abcfolder/TheFileToReceiveParam',{paramToPass });}

I want to get paramToPass in TheFileToReceiveParam when the page is open but I dont know how to do this.

Would be a big help if anyone can help.

1 Answers1

0

Once you have passed your parameter this way :

this.props.history.push('/my-path', { myParam: paramToPass });

You can retrieve this parameter using the 'location' property of your destination component:

this.props.location.state.myParam;

According to the React Router documentation, here's an example of what the location object looks like:

{
  key: 'ac3df4', // not with HashHistory!
  pathname: '/somewhere'
  search: '?some=search-string',
  hash: '#howdy',
  state: {
    [userDefined]: true
  }
}
alextouzel
  • 218
  • 1
  • 18