Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React router not showing browser history

Tags:

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')
);
like image 948
stackjlei Avatar asked May 19 '17 06:05

stackjlei


People also ask

Does React Router use history API?

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.

Is React Router Dom deprecated?

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.

What is the difference between Router and BrowserRouter React?

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.


1 Answers

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'
like image 71
Preview Avatar answered Sep 18 '22 13:09

Preview