I am using react-router with react js and i following their documentation but facing this error
while compiling it shows the error,
TypeError: _this.
This is because things changed in React Router starting with 4.0.0. You should now use BrowserRouter
from react-router-dom
package when you were using browserHistory
. So your code will looks like:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import { BrowserRouter, Route } from 'react-router-dom';
ReactDOM.render(
, document.getElementById('root')
);
Of course, you'll need to install react-router-dom
first.
Also note that if you're using more than one Route
element, you'll have to use a Switch
as explained in this answer.