Reputation: 5049
So I'm trying to use history
in React, but it seems to be moved around a lot. I found this:
but it just says that 'react-router' does not contain an export named 'browserHistory'.
How can I solve it? Where can I find history? All answers I found were around 1.5 years old.
Upvotes: 2
Views: 3338
Reputation: 47172
You're looking for the BrowserRouter
.
import { BrowserRouter } from 'react-router';
browserHistory
is something that existed in v2/v3 but was rewritten into BrowserRouter
in v4.
There is a migration guide here that should help you.
Upvotes: 2
Reputation: 4333
You no longer have browserHistory
apparently. So you can do this instead,
<Route>
<Header />
</Route>
and you can do
function Header(props) {
// props.history and props.location are available now inside this component
}
and then you can do props.history.push
or whatever if that is what you want to do.
The link you have is for the older version of react-router
so check out react-router 4
Upvotes: 0
Reputation: 281706
history Api
has been moved to a separate history package
In order to create browserHistory
, you install history like
npm install -S history
and write
import createHistory from "history/createBrowserHistory"
const browserHistory = createHistory()
export { browserHistory };
However in react-router-v4
an equivalent of Router
with browserHistory
is BrowserRouter
Upvotes: 0