in React JS by
Q:

How to get history on React Router v4?

1 Answer

0 votes
by
  1. Create a module that exports a history object and import this module across the project.

    For example, create history.js file:

    import { createBrowserHistory } from 'history'
    
    export default createBrowserHistory({
      /* pass a configuration object here if needed */
    })
  2. You should use the <Router> component instead of built-in routers. Imported the above history.js inside index.js file:

    import { Router } from 'react-router-dom'
    import history from './history'
    import App from './App'
    
    ReactDOM.render((
      <Router history={history}>
        <App />
      </Router>
    ), holder)
  3. You can also use push method of history object similar to built-in history object:

    // some-other-file.js
    import history from './history'
    
    history.push('/go-here')
Click here to read more about React JS
Click here to read more about Insurance

Related questions

+1 vote
asked Mar 2, 2020 in React JS by RShastri
0 votes
asked Mar 2, 2020 in React JS by RShastri
0 votes
asked Nov 26, 2019 in React JS by AdilsonLima
0 votes
asked Feb 24 in React JS by SakshiSharma
0 votes
asked May 20, 2020 in React JS by GeorgeBell
0 votes
0 votes
0 votes
asked Mar 3, 2020 in React JS by miceperry
+1 vote
...