1

I'm trying to change the page in react-router by calling history.push method. but I need an event to listen to page url changes and update context by getting query parameters. how can I declare that event?

reza
  • 1,316
  • 3
  • 13
  • 29

2 Answers2

0

One way to do it is to change the state with the url parameters right after history.push (which is synchronous) which will update your UI.

Reading url parameters from url should be done only on initial mount.

0

You can send the data required on the next page in history.push.

 this.props.history.push("/url", { id: 123 })

then you can access the parsed data in the next component by following code,

const state = this.props.location.state
akhil choudhary
  • 684
  • 5
  • 6
  • I don't want using props to pass data through components. because this data is used in several component and 'll mess in code – reza Dec 10 '19 at 13:21