查询字符串与反应路由器路由不匹配的URL [英] URL with query string not matching react-router route
本文介绍了查询字符串与反应路由器路由不匹配的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于此React路由器配置:
Given this React router configuration:
<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路由而不是第一个?
Why is http://localhost:8080/farm/average?period=day
only matching the catch-all route and not the first one?
推荐答案
查询字符串参数不需要包含在< Route>
定义中。
Query string parameters don't need to be included in the <Route>
definition.
将路线定义更改为< Route path =/ farm /:typecomponent = {Farm} />
解决了这个问题。
Changing the route definition to <Route path="/farm/:type" component={Farm} />
solved the problem.
查询字符串参数仍在 props.location.query
这篇关于查询字符串与反应路由器路由不匹配的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文