2015-11-16 211 views
0

this.props.children困惑我的路由器是這樣的:與反應路由器V1.0.0

<Route path="/" component={App}> 
    <IndexRoute component={Dashboard} /> 
    <Route path="info" component={Info}> 
    <Route path="c/:cid" component={CompanyDetail} /> 
    <Route path="p/:pid" component={ProjectDetail} /> 
    </Route> 
</Route> 

我的信息組件是一個高階組件連接的react-redux

作爲react-router v1.0.0中的更改,如果達到/info/c/123,Info組件中的this.props.children應代表CompanyDetail組件。但是我得到這個當我嘗試達到/info

enter image description here

我似乎的this.props.children在信息單元的值是本身?如果我嘗試訪問/info/c/123,也得到了這個問題,Info組件包含Info組件本身,其中包含CompanyDetail組件。

enter image description here

這混亂對我來說,任何想法?

回答

0

我認爲你應該將CompanyDetail和ProjectDetail路由定義爲Info路由的子路由。

如:

<Route path="info" component={Info}> 
    <Route path="info/c/:cid" component={CompanyDetail} /> 
    <Route path="info/p/:pid" component={ProjectDetail} /> 
</Route> 
+0

對不起我的錯字,我確定了這樣的路線,並且我在上面修正了它。我添加了反應開發工具的屏幕截圖。 –

+0

你有沒有試過'path =「info/c /:cid」'這樣,有什麼想法? – TIJ

0

我固定它自己。我發現原來的代碼在我的應用程序組件,它包含代碼:

React.cloneElement(this.props.children, {...this.props}) 

防止拷貝this.props.children兒童固定。