我有一門課程按照順序來學習React.js
。這是一個偉大的,非常有幫助的,但我一直在工作中遇到錯誤react-router
從我讀過的時候,我正在嘗試學習,並同時理解它,所以會讓它更加混亂。
錯誤
warning.js:36警告:無法丙類型:該道具
history
被標記 如Router
必需的,但它的值是undefined
。 在路由器(在index.js:12)
問題
請能夠解釋爲什麼這不會在V4工作
<Router history={browserHistory}>
"dependencies": {
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-router": "^4.1.1"
},
例
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/" component={Home} />
<Route path="/services" component={Services} />
<Route path="/portfolio" component={Portfolio} />
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
<Route path="*" component={Fourofour} />
</Router>
,
document.getElementById('root')
);
一些輕
進口
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, browserHistory } from 'react-router'
import Fourofour from './containers/fourofour/Fourofour';
import Home from './containers/home/Home';
import Services from './containers/services/Services';
import Portfolio from './containers/portfolio/Portfolio';
import About from './containers/about/About';
import Contact from './containers/contact/Contact';
你的意思是「這不適用於V4」?它會工作。代碼將被編譯。 –
嘿,謝謝你的幫助。我要解決我的錯誤。如果你有時間你會介意看我目前的項目嗎? https://github.com/wuno/react-components – wuno
你看到什麼錯誤? –