2016-07-07 165 views
4

我開發我的項目與react-router反應路由器不渲染組件

下面是我的代碼。

const App2 = React.createClass({ 
    render() { 
     return (
      <div> 
       <Link to="index">index</Link> 
       <Link to="favorite">favorite</Link> 
       <Link to="myPage">myPage</Link> 
       {this.props.children} 
      </div> 
     ) 
    } 
}); 

var app = ReactDOM.render (
    <Router history={browserHistory}> 
     <Route path="/" component={App2}> 
      <Route path="index" component={PhotoFeedWrapper}/> 
      <Route path="favorite" component={FavoriteWrapper}/> 
      <Route path="myPage" component={MyPageWrapper}/> 
     </Route> 
    </Router>, 
    document.getElementById('app') 
); 

我想我的代碼是正確的。但是,如下所示,這呈現爲空。

<div id="app"><!-- react-empty: 1 --></div> 

沒有腳本錯誤。

我做錯了什麼?

+1

您是如何訪問它的?使用'http:// localhost/index'?另外,你可以發佈你的其他組件,看看它們是否正確? –

+0

@WilliamMartins不,我訪問它'http:// localhost:8080/contextPath/index'。我不在節點上使用它。我用它與春天和UMD構建。所以,我喜歡那樣使用。其他組件是正確的 –

+0

這很奇怪,你的鏈接被渲染? –

回答

1

Link組件當前僅支持絕對路徑。您必須更改爲:

<Link to="/index">index</Link> 
<Link to="/favorite">favorite</Link> 
<Link to="/myPage">myPage</Link> 
+0

我看到你的'鏈接'設置,然後我立即發佈這個。然後我意識到這並不能回答你原來的問題。但它確實在您的代碼中修復了另一個錯誤。 :P – xiaofan2406