Sometimes, we want to change the URL in react-router v4 without using Redirect or Link with JavaScript.
In this article, we’ll look at how to change the URL in react-router v4 without using Redirect or Link with JavaScript.
How to change the URL in react-router v4 without using Redirect or Link with JavaScript?
To change the URL in react-router v4 without using Redirect or Link with JavaScript, we call the history.push method.
For instance, we write
this.props.history.push("/foo");
to call history.push with '/foo' to navigate to /foo.
Conclusion
To change the URL in react-router v4 without using Redirect or Link with JavaScript, we call the history.push method.