2015-11-05 103 views
0

我有這個代碼:路由器沒有定義

import { Router, Route } from 'react-router' 

render((
    <Router> 
    <Route path="/" component={ App }> 
     <Route path="page1" component={ Page1 }/> 
     <Route path="page2" component={ Page2 }/> 
     <Route path="page3" component={ Page3 }/> 
    </Route> 
    </Router> 
), document.getElementById('app-container')); 

而且具有的WebPack編譯它,babeljs後,谷歌瀏覽器顯示錯誤:

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). 
Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. 

當我想通原因是路由器不作爲'react-router'屬性導出,因此Router組件是'undefined'

我使用react-router版本0.13.5。有什麼方法可以正確使用它?

+0

我試過react-router版本^ 1.0.0-rc1,現在相同的代碼工作得很好。但我仍然困惑 – taydakov

回答

0

這是v0.13.x和v1.0.0預發佈版之間對React Router的API的更改。只是你可以使用的代碼例如1.0.0-rc1 API,但不具有不同的v0.13.x API。