如果我想要有一个路线层次结构,并将事件状态应用于我的导航,但某些级别的导航纯粹是逻辑性的。
例如,如果我这样做
<Route component={App} path="/" >
<Route path="example" component={empty}>
<Route path="ex1" component={ex1} />
<Route path="ex2" component={ex2} />
<IndexRedirect to="ex1" />
</Route>
</Route>
我的导航节点示例正确应用了事件状态,但随后我必须创建一个空组件,它只渲染子组件。
或者,我可以展平路线,这意味着我不再需要创建空组件,但我不再获得事件导航状态。
有什么好的解决办法吗? (我使用的是最新的react-router v2.0.0rc5)
最佳答案
您可以省略空组件。我会把你的例子写成:
<Route path="/" component={App} >
<Route path="example">
<IndexRedirect to="ex1" />
<Route path="ex1" component={ex1} />
<Route path="ex2" component={ex2} />
</Route>
</Route>
这被认为是惯用的。
关于javascript - 使用 React Router 的分层路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34872935/