I'm learning from this tutorial but I keep getting this error:
'react-router' does not contain an export named 'browserHistory'.
The file that has react-router is this:
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, browserHistory } from 'react-router';
import routes from './routes';
ReactDOM.render(
<Router history={browserHistory} routes={routes} />,
document.getElementById('root')
);
React Router uses the history package, which builds on the browser history API to provide an interface to which we can use easily in React apps. location - (object) The current location. May have the following properties: pathname - (string) The path of the URL.
react-dom : ReactDOM.render has been deprecated. Using it will warn and run your app in React 17 mode. react-dom : ReactDOM.hydrate has been deprecated. Using it will warn and run your app in React 17 mode.
The main difference between the two is the way they store the URL and communicate with your web server. A <BrowserRouter> uses regular URL paths. These are generally the best-looking URLs, but they require your server to be configured correctly.
You need to get browserHistory
from the history module now.
import createHistory from 'history/createBrowserHistory'
Note that they changed the module API recently so if you are using the latest version the import slightly changed:
import { createBrowserHistory } from 'history'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With