【问题标题】:React router allow path with dot(.)反应路由器允许带点(。)的路径
【发布时间】:2020-03-08 09:18:30
【问题描述】:

我试图添加正则表达式以允许如下路径,但我无法使其工作。
例如:

  1. '/hello/search.apple.tree'
  2. '/hello/search.mango.tr'
  3. '/view/location.chicago.illinois'
  4. '/view/location.boston.ma'

【问题讨论】:

标签: reactjs react-router react-router-v4 react-router-dom


【解决方案1】:

React 使用库作为路径 (see react documentation)
该库被称为path-to-regexp

您必须检查可以与此库一起使用的有效路径。

这是一个您可以现场试用的演示:valid path demo

【讨论】:

    【解决方案2】:

    也许你可以通过将这个添加到你的 webpack 开发服务器配置来解决。

    historyApiFallback: {
        disableDotRule: true
    }
    

    来自:https://github.com/ReactTraining/react-router/issues/3409

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-17
      • 2017-05-27
      • 1970-01-01
      • 2017-08-07
      • 2016-06-06
      • 2019-08-03
      • 1970-01-01
      相关资源
      最近更新 更多