代码之家  ›  专栏  ›  技术社区  ›  Adam

React Router V6-useRoutes()路径正则表达式

  •  0
  • Adam  · 技术社区  · 4 年前

    顺便说一句,v6看起来很棒!!

    在v4之前,我将执行以下操作。仅当路径为/profile/<时才匹配;10位数字>。。。。(否是配置文件id)。有没有一种方法可以在v6中访问这样的正则表达式url?

    <Route path="/profile/:userid([0-9]{10})" component={Profile} />
    

    同样在V4中,我能够在括号中的Param之后限制Param选项-“:type(email | forget)”。在v6中有这样做的方法吗?

    <Route exact path="/login/:type(email|forgot)" component={Login} />
    

    { path: '/profile/:userid([0-9]{10})', element: <Profile /> }
    
    { path: '/login/:type(email|forgot)', element: <Login /> }
    

    我知道第二封邮件(电子邮件|忘记)我可以使用“children”,这很好。我只是想问问。

    任何信息都可以。 非常感谢!!

    0 回复  |  直到 4 年前
        1
  •  0
  •   Adam    4 年前

    我直接写信给React Router V6开发团队,目前path中不支持regex。有一个小机会,它可能会被添加。。。

    以下是回应- https://github.com/remix-run/react-router/discussions/8132