【问题标题】:React router path as an array将路由器路径反应为数组
【发布时间】:2019-03-13 15:13:20
【问题描述】:

我有这样的代码:

<BrowserRouter>
  <Switch>
    <Route path="/" exact component={component1} />
    <Route path="/somewhere/:something" component={component2} />
  </Switch>
</BrowserRouter>

我试过这个,因为最后我想用相同的组件/结果匹配多个路径:

<BrowserRouter>
  <Switch>
    <Route path={["/somewhere/:something","/somewhere2/:something"]} component={component2} />
  </Switch>
</BrowserRouter>

并且路径匹配,但我的参数 (:something) 没有传递给它。知道为什么吗? react-router 的文档tells me:

path-to-regexp@^1.7.0 可以理解的任何有效 URL 路径或路径数组。

【问题讨论】:

  • 事实上,我注意到错误:失败的道具类型:无效的道具path 类型为array 提供给Route,预期string。这与文档不一致

标签: react-router


【解决方案1】:

该功能最近才出现added to React-Router。您需要升级您的 react-router 安装,以便能够匹配文档并使用该功能。

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 2023-04-03
    • 2020-01-21
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多