2

When I want to go from a route to another with this.props.history.push("/"), also I want to send some additional data, for example: this.props.history.push('/postDetail', {data: item}). But I do not know how where to define this data in the class where we went.

Thank you in advance

Fabio Plaka
  • 138
  • 2
  • 12
  • 1
    You can se it here https://stackoverflow.com/questions/44121069/how-to-pass-params-with-history-push-link-redirect-in-react-router-v4 – vaske Mar 16 '20 at 15:35

1 Answers1

0

You can send a prop called state that comes from the router:

this.props.history.push({
 pathname: '/postDetail',
 state: { data: item }
});

So now your component attached with that route will have the location prop available, inside the location object lies the state that you have passed. More info here: https://reacttraining.com/react-router/web/api/history

jean182
  • 3,213
  • 2
  • 16
  • 27