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

前端之家收集整理的这篇文章主要介绍了reactjs – react-router – 创建没有组件嵌套的嵌套路由前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这样的路由配置.
  1. <Route path="group/:groupId" component={NonPropertyView}>
  2. <Route path="group/:groupId/line/:lineId" component={NonPropertyView} />
  3. <Route path="group/:groupId/line/:lineId/property/:propertyId" component={PropertyView} />

但我可以这样做吗?

  1. <Route path="group/:groupId" component={NonPropertyView}>
  2. <Route path="line/:lineId" component={NonPropertyView}>
  3. <Route path="property/:propertyId" component={PropertyView} />
  4. </Route>
  5. </Route>

我正在寻找的是一个选项,只需渲染叶子路径的组件而不渲染父路径组件.这可能吗?

是 – 使用< IndexRoute> s.例如,将上面写为:
  1. <Route path="group/:groupId">
  2. <IndexRoute component={NonPropertyView} />
  3. <Route path="line/:lineId">
  4. <IndexRoute component={NonPropertyView} />
  5. <Route path="property/:propertyId" component={PropertyView} />
  6. </Route>
  7. </Route>

猜你在找的React相关文章