【发布时间】:2017-06-26 16:44:57
【问题描述】:
我正在使用 react-router 3.0.2 并尝试使用查询字符串配置路由器路径。这就是我配置路由器的方式:
<Router history={browserHistory}>
<Route path="abc/login.do" component={LoginComponent}/>
<Route path="abc/publicLoginID.do?phase=def" component={VerifyComponent} />
<Route path="abc/publicLoginID.do?phase=ghi" component={ImageComponent}/>
<Route path="*" component={LoginComponent}/>
</Router>
我知道这不是在“路线”中指定查询字符串 (?) 的正确方法。如何确保当用户在 url 中输入“http://localhost:3000/abc/publicLoginID.do?phase=def”时,会显示“VerifyComponent”,当他在 url 中输入“http://localhost:3000/abc/publicLoginID.do?phase=ghi”时,会显示“ImageComponent”。
我确实在这里检查了一些案例:react-router match query string 和 Querystring in react-router,但无法弄清楚如何使其工作。
【问题讨论】:
-
您可以编写一个包装器组件,它将根据查询参数切换要呈现的内容
标签: reactjs react-router query-string