How to push to History in React Router v4?

You can use the history methods outside of your components. Try by the following way. First, create a history object used the history package: // src/history.js import { createBrowserHistory } from ‘history’; export default createBrowserHistory(); Then wrap it in <Router> (please note, you should use import { Router } instead of import { BrowserRouter as … Read more

Programmatically Navigate using react-router

Considering you are using react-router v4 Use your component with withRouter and use history.push from props to change the route. You need to make use of withRouter only when your component is not receiving the Router props, this may happen in cases when your component is a nested child of a component rendered by the … Read more

tech