【问题标题】:Hierarchical routes with react router带有反应路由器的分层路由
【发布时间】:2016-04-24 16:46:16
【问题描述】:

如果我想要一个层次结构的路线,将活动状态应用于我的导航,但导航的某些级别是纯逻辑的。

例如,如果我这样做

<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)

【问题讨论】:

    标签: javascript reactjs react-router


    【解决方案1】:

    您可以省略空组件。我会把你的例子写成:

    <Route path="/" component={App} >
      <Route path="example">
        <IndexRedirect to="ex1" />
        <Route path="ex1" component={ex1} />
        <Route path="ex2" component={ex2} />
      </Route>
    </Route>
    

    这会被认为是惯用的。

    【讨论】:

      猜你喜欢
      • 2017-07-23
      • 2020-08-24
      • 2016-09-10
      • 2017-05-19
      • 2017-05-27
      • 1970-01-01
      • 2018-06-02
      • 2020-07-29
      • 1970-01-01
      相关资源
      最近更新 更多