Categories
React Answers

How to use react-router 4.0 to refresh current route and not reload the whole page?

Spread the love

Sometimes, we want to use react-router 4.0 to refresh current route and not reload the whole page.

In this article, we’ll look at how to use react-router 4.0 to refresh current route and not reload the whole page.

How to use react-router 4.0 to refresh current route and not reload the whole page?

To use react-router 4.0 to refresh current route and not reload the whole page, we can call history.push and then history.goBack.

For instance, we write

history.push('/temp');
history.goBack();

to call history.push with any path name to navigate.

Then we call history.goBack to go back to the original route.

This will refresh the current route without reloading the whole page.

Conclusion

To use react-router 4.0 to refresh current route and not reload the whole page, we can call history.push and then history.goBack.

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 *