鉴于此 React 路由器配置:
<Router history={browserHistory}>
<Route path="/farm/:type?period=:period" component={Farm} />
<Route path="/pen/:penId" component={Pen} />
<Route path="/pen/:penId/cow/:cowId" component={Cow} />
<Route path="*" component={Farm} />
</Router>
为什么 http://localhost:8080/farm/average?period=day
只匹配 catch-all 路由而不是第一个?
最佳答案
查询字符串参数不需要包含在 <Route>
中定义。
将路由定义更改为 <Route path="/farm/:type" component={Farm} />
解决了问题。
查询字符串参数在props.location.query
下仍然可用
关于javascript - 查询字符串与 react-router 路由不匹配的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39728059/