15

I'm trying to use a router for my React application. I tried something I'd been using a while back, but can't seem to get it going. Has hashHistory been removed/reformatted in React Router v4?

<Router history={hashHistory}>
  <Route path='/' component={MainContainer} />
</Router>
Andrew Li
  • 47,104
  • 10
  • 106
  • 132
Petter Östergren
  • 765
  • 3
  • 9
  • 23

1 Answers1

40

Use a HashRouter. They got rid of individual histories such as browserHistory and hashHistory and instead replaced them with BrowserRouter and HashRouter components respectively in React Router v4:

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

<HashRouter>
  …
</HashRouter>

Note that HashRouter comes from react-router-dom, not the core react-router package.

Andrew Li
  • 47,104
  • 10
  • 106
  • 132