React-router: 4.1.1 hashHistory not

Created on 31 May 2017  路  1Comment  路  Source: ReactTraining/react-router

'react-router' does not contain an export named 'hashHistory'.

Most helpful comment

The <HashRouter> creates a hash history for you. For most projects, that should be all you need to do.

import { HashRouter } from 'react-router-dom';

ReactDOM.render((
  <HashRouter>
    <App />
  </HashRouter>
), holder);

If you need to access the history object outside of your components, you will need to create your own history object and pass it to the <Router>.

// history.js
import { createHashHistory } from 'history';
export default createHashHistory();

// index.js
import { Router } from 'react-router-dom';
import history from './history';

ReactDOM.render((
  <Router history={history}>
    <App />
  </Router>
), holder);

>All comments

The <HashRouter> creates a hash history for you. For most projects, that should be all you need to do.

import { HashRouter } from 'react-router-dom';

ReactDOM.render((
  <HashRouter>
    <App />
  </HashRouter>
), holder);

If you need to access the history object outside of your components, you will need to create your own history object and pass it to the <Router>.

// history.js
import { createHashHistory } from 'history';
export default createHashHistory();

// index.js
import { Router } from 'react-router-dom';
import history from './history';

ReactDOM.render((
  <Router history={history}>
    <App />
  </Router>
), holder);
Was this page helpful?
0 / 5 - 0 ratings