我想你可以有一個這樣的佈局:
<App>
<Navbar /> { /* Here you show the username also, this view will depend on props */ }
<Layout /> { /* Here you may have the content and the sidenav */ }
</App>
應用是頂部部件,即通過道具例如在渲染()中的主容器,你將有
// You should treat this as a Page component, the one that grabs
// data and passes it as props to another components
export default class AppPage extends React.Component {
render() {
return (<AppLayout { ...this.props } />);
}
}
export default class AppLayout extends React.Component {
render() {
return (
<Navbar someProp={ this.props.someProp } />
{ this.props.children }
);
}
}
路由器可以是例如:
<Router history={ browserHistory }>
<Route path="/" component={ App }>
<IndexRoute component={ Landing } />
<Route path="/index" component={ Layout } />
</Route>
</Router>
IndexRoute是'/',你可以說哪些組件應該是我們的例如,如果您路由到/ layout {this.props。兒童}在AppLayout將渲染爲<Layout />
組件。
我建議你閱讀這篇文章:https://facebook.github.io/react/docs/thinking-in-react.html 更好地瞭解如何應對作品...希望它幫助
1,它應該是在導航欄的組成部分。 2.即使反應路由器是一個不錯的選擇,你有其他的選擇,你可以檢查。 3.我不知道這麼多的流量,你應該閱讀他們的GitHub文檔。 4.您可以在componentDidMount時創建$ .get,因爲React對組件執行某些類型的事務時具有「回調」。 5.終極版是描述陳述如何變化的減速,這是更先進的,但你也可以看一下,如果你要開始它可能看起來很複雜.. – MiGu3X
如果過濾器值應通過導航通過?例如,這可能是一個「年份」過濾器,用於過濾顯示的當前數據?我是否爲此使用上下文? – Nsevens