[英]leading optional path parameters in React Router v6
In v5 I use next path regex:在 v5 中,我使用下一个路径正则表达式:
/:locale?/:city?/mobile
In v6 it doesn't work.在 v6 中它不起作用。 Tried to use array in
path
prop, but it doesn't supported尝试在
path
道具中使用数组,但不支持
How I can refactor these in v6?我如何在 v6 中重构这些?
See this Github issue: https://github.com/remix-run/react-router/issues/7285请参阅此 Github 问题: https://github.com/remix-run/react-router/issues/7285
React Router v6 apparently doesn't support optional params anymore. React Router v6 显然不再支持可选参数。 Instead, you need to create a route per combination of params.
相反,您需要为每个参数组合创建一个路由。 In your case I think it may look something like this:
在你的情况下,我认为它可能看起来像这样:
<Route path="/:locale">
<Route path="/:city" element={<Page />} />
<Route path="" element={<Page />} />
</Route>
<Route path="/:mobile" element={<Page />} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.