Categories
React Answers

How to change the URL in react-router v4 without using Redirect or Link with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *