Ada*_*dam 11 reactjs react-router
我知道 React-router-dom v6 处于测试阶段,但我正在使用它,并且有几个关于 useRoutes() 和路径和正则表达式的问题。
顺便说一句 - v6 看起来很棒!
在 v4 之前我会执行以下操作。仅当路径为 /profile/<10 位数字>....(不是 profile_id)时,它才会匹配。有没有办法在 v6 中像这样的正则表达式 url?
<Route path="/profile/:userid([0-9]{10})" component={Profile} />
Run Code Online (Sandbox Code Playgroud)
同样在 V4 中,我能够限制括号中的参数后面的参数选项 - ':type(email|forgot)'。v6 有办法做到这一点吗?
<Route exact path="/login/:type(email|forgot)" component={Login} />
Run Code Online (Sandbox Code Playgroud)
我的以下尝试没有成功。
{ path: '/profile/:userid([0-9]{10})', element: <Profile /> }
{ path: '/login/:type(email|forgot)', element: <Login /> }
Run Code Online (Sandbox Code Playgroud)
我知道第二个(电子邮件|忘记)我可以使用“孩子”,这很好。我只是想问一下。
它的 profile_id 10 位正则表达式会很棒。如果不满足该条件,则宁愿不路由到该组件。
任何信息都会很好。非常感谢!!
Ada*_*dam 18
我直接写信给 React Router V6 开发团队,目前路径中不支持正则表达式。可能性很小,可能会被添加...
这是响应 - https://github.com/remix-run/react-router/discussions/8132
归档时间: |
|
查看次数: |
11445 次 |
最近记录: |