Pushing to History in React Router v4

In the current version of React Router (v3), you can accept a server response and use browserHistory.push to go to the appropriate response page. However, this isn't available in v4 and you have to go about it a different way.

You can use the history methods outside of your components. Try by the following way.

First, create a history object used the history package:

Then wrap it in <Router> (please note, you should use import { Router } instead of import { BrowserRouter as Router }):

Change your current location from any place, for example:

Note: You can also see a slightly different example in React Router FAQ.

As Principal Design Technologist in Alexa Voice Shopping at Amazon, I design and build prototypes that define the future of voice and multi-model shopping.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store