Warning: Failed prop type: The prop history
is marked as required in Router
, but its value is undefined
.
"react-router": "^5.1.2"
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route } from 'react-router'
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render((
<Router>
<Route path="/" component={App}/>
{/* <Route path="/repos" component={Repos}/>
<Route path="/about" component={About}/> */}
</Router>
), document.getElementById('root'))
serviceWorker.unregister();
查了好久,都說是版本問題住拭,換了n個版本楣号,還是會報錯逆趋,后來看到說要從react-router-dom引入,所以安裝了以后,像下面這樣寫纵寝,不知道有沒有跟我一樣腦回路不一般拢锹。
import { Router, Route } from 'react-router-dom'
依然報錯,對于我這樣的小白來說真的是很折磨了鳞滨,后來終于發(fā)現(xiàn)還是格式不對,主要原因還是由于Router更新api所導(dǎo)致蟆淀,具體解決方案拯啦,參照React api文檔中內(nèi)容 https://reacttraining.com/react-router/web/api/Route 將路由引入方式作出如下修改即可。最后改成這樣終于好了熔任。
import { HashRouter as Router, Route } from 'react-router-dom'
雖然是個很小的問題褒链,解決了也很高興,我就是這么的容易滿足笋敞,不過react-router中還是有很多東西是我不知道的,學(xué)習的路還很長荠瘪,加油吧夯巷!