路由匹配规则是从上到下执行,一旦发现匹配,就不再其余的规则了。

(1):paramName

:paramName匹配URL的一个部分,直到遇到下一个/、?、#为止。这个路径参数可以通过this.props.params.paramName取出。 <Route path="/hello/:name"> // 匹配 /hello/michael // 匹配 /hello/ryan

(2)()

()表示URL的这个部分是可选的。 <Route path="/hello(/:name)"> // 匹配 /hello // 匹配 /hello/michael // 匹配 /hello/ryan

(3)*

*匹配任意字符,直到模式里面的下一个字符为止。匹配方式是非贪婪模式。 <Route path="/files/*.*"> // 匹配 /files/hello.jpg // 匹配 /files/hello.html (4) **

** 匹配任意字符,直到下一个/、?、#为止。匹配方式是贪婪模式。 <Route path="/**/*.jpg"> // 匹配 /files/hello.jpg // 匹配 /files/path/to/file.jpg

相关文章:

  • 2022-12-23
  • 2023-03-19
  • 2022-12-23
  • 2021-09-01
  • 2021-06-20
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-03
  • 2022-12-23
  • 2022-01-20
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案