我可以在react-router basename路由中使用路径参数

时间:2017-12-15 21:52:24

标签: reactjs react-router-v4

我找到了类似的SO Postunanswered post,但是,当您需要动态路径(路径参数)时,您会怎么做?

/calendar/:year/:month/:day/event类似,例如,/calendar/11/4/21/event

1 个答案:

答案 0 :(得分:1)

The basename that you can pass to a router (e.g. <BrowserRouter basename='/thing'>) is not dynamic. You should think of the basename as the static path to the root directory where your app is located (although this might not be a literal path since you're most likely using a dynamic server).

Occasionally I have seen requests for dynamic basenames, usually when someone has language sections of their site (example.com/en/about and example.com/zh/about). The usual reason for wanting to include this information in the basename is so that it doesn't have to be included in URIs. However, the basename isn't supposed to contain information about the route; any data that isn't going to be the same for every single route in your application should not be part of the basename.