【发布时间】:2020-11-16 06:09:47
【问题描述】:
我有一个页面路径 /movies?categoryId=21213 在这个页面上,我有一部分演员,点击它应该重定向到 /movies?categoryId=21213/actor?actorId=234324234
我应该如何正确描述以使用演员渲染我的最新组件? 我试过了
<Route path=`/movies/:categoryId?/:actorId?`/>
但这不起作用
【问题讨论】:
-
我的理解是查询字符串参数不直接由 react-router 处理,您可以使用多个路径:
<Route path={['/movies/:categoryId/:actorId','/movies/:categoryId', '/movies/']} />或使用路由应该制作的 location 属性处理您自己的查询参数在您的组件上可用。 -
这是一个较旧的问题,其中包含有关如何将查询参数与反应路由器一起使用的答案。 https://stackoverflow.com/questions/43216569/how-to-get-query-parameters-in-react-router-v4
标签: reactjs parameters routes react-router