2016-09-27 75 views
1

鉴于这一阵营路由器配置:URL查询字符串不匹配反应路由器的路由

<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仅符合包罗万象的路线,而不是第一个?

回答

2

查询字符串参数不需要包含在<Route>定义中。

将路由定义更改为<Route path="/farm/:type" component={Farm} /> 解决了该问题。

查询字符串参数仍然可用props.location.query