react-router-创建没有组件嵌套的嵌套路由

吉汀

我有这样的路由配置。

<Route path="group/:groupId" component={NonPropertyView}>
<Route path="group/:groupId/line/:lineId" component={NonPropertyView} />
<Route path="group/:groupId/line/:lineId/property/:propertyId" component={PropertyView} />

但是我可以这样做吗?

<Route path="group/:groupId" component={NonPropertyView}>
  <Route path="line/:lineId" component={NonPropertyView}>
    <Route path="property/:propertyId" component={PropertyView} />
  </Route>
</Route>

我正在寻找的是仅为Component叶路线渲染而不渲染父路线的选项Component这可能吗?

泰翁

是的-使用<IndexRoute>s。例如,将上面的代码写为:

<Route path="group/:groupId">
  <IndexRoute component={NonPropertyView} />
  <Route path="line/:lineId">
    <IndexRoute component={NonPropertyView} />
    <Route path="property/:propertyId" component={PropertyView} />
  </Route>
</Route>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章