所以,我一直在与 react-router-dom
合作。我的问题是我正在使用嵌套路由。我想让它在 URL 中没有父路由的情况下路由。
我当前的代码是。
<Route path= "/dashboard/some-page" component={someComponent}/>
而我想做的是
<Route path="/some-page" component={someComponent}/>
。
答案 0 :(得分:0)
目前,您不能。 react-router-dom
只匹配完整路径。在即将发布的第 6 版中,他们添加了该功能,但目前仍处于测试阶段。这不是替代品的下降; API 已更改,因此需要进行一些重组。
https://reacttraining.com/blog/react-router-v6-pre/#nested-routes-and-layouts