Answer the question
In order to leave comments, you need to log in
React Router giving weird error?
Help me understand, I started learning react and when creating simple routes I came across an error:
Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`.
in Router
, as well as another one:
Uncaught TypeError: Cannot read property 'location' of undefined
Here is the code:
import React from 'react';
import ReactDom from 'react-dom';
import {Router, Route} from 'react-router';
import NewComponent from './new-component-1';
import About from './about';
ReactDom.render(
<Router>
<Route path={'/'} component={ App } />
<Route path={'about'} component={ About } />
</Router>,
document.getElementById('app')
);
Answer the question
In order to leave comments, you need to log in
That's right, use the BrowserRouter from react-route-dom and switch between Routes using Switch
import React from 'react';
import ReactDom from 'react-dom';
import {BrowserRouter, Route, Switch} from 'react-router-dom';
import NewComponent from './new-component-1';
import About from './about';
ReactDom.render(
<BrowserRouter>
<Switch>
<Route path={'/'} component={ App } />
<Route path={'about'} component={ About } />
</Switch>
</BrowserRouter>,
document.getElementById('app')
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question