【发布时间】:2017-05-05 14:28:53
【问题描述】:
我有一个简单的单页 React 应用设置,带有导航栏、内容和页脚。导航栏本身由两个子导航栏组成:一个对每个页面都相同,另一个应该根据路由动态变化(特定于页面的导航栏)。
所以基本上,我有一个顶级组件Container:
<Navbar>
<Navbar.Main/>
<Navbar.Page/>
</Navbar>
{this.props.children}
<Footer/>
以及App中定义的路由:
<Router history={browserHistory}>
<Route component={Container}>
<IndexRoute component={Home} />
<Route path="/" component={Home} />
<Route path="/contact" component={Contact} />
<Route path="/about" component={About} />
<Route path="*" component={NotFound} />
</Route>
</Router>
虽然页面内容会在 {this.props.children} 部分内发生变化,但我想根据路由更改 <Navbar.Page/> 导航栏组件的内容(联系人页面应该具有特定于联系人的导航栏等)。
我知道我可以通过在页面内渲染页面导航栏轻松实现这一点,但我想继续在导航栏中进行渲染。
【问题讨论】:
-
我在这里找到了解决方案:rabbitfighter.net/?p=1027
-
是不是和我的回答一样,除了我解释了逻辑。
标签: reactjs components react-router