2016-03-10 87 views
1

在反應路由器有一種方法來有子路由但不顯示父組件?我試圖在我的應用程序中顯示麪包屑,所以我切換到有子路線,但我不想以「主/細節」類型佈局顯示父組件。我只想讓子組件顯示爲自己導航,但似乎如果在父組件中某處不包含{this.props.children},那麼子組件將永遠不會呈現。如果填充this.props.children在反應路由器中隱藏父組件

一分劈我試過被看到,而不是顯示在頁面的其餘部分呈現類似

if(this.props.children) { 
    return (this.props.children) 
} else { 
    return /**rest of render method**/ 
} 

但這種感覺就像一個壞的解決方案。

回答

1

我有你想要做什麼很難理解,但似乎<IndexRoute>可以幫助你,因爲這可以讓你分辨你/portal對做什麼/portal/feature

<Route path="/portal" component={ComponentContainingBreadcrumbs}> 
    <IndexRoute component={ComponentWithRestofRenderMethodFromYourExample} /> 
    <Route path="child1" component={Child1} /> 
    <Route path="child2" component={Child2} /> 
</Route>