在 React Router 3 中,如何与包含查询参数的路由精确匹配?
像这样的东西,
<Route path="about?qs1=:qs&qs2=:qs2" component={About} />
在 React Router 3 中,如何与包含查询参数的路由精确匹配?
像这样的东西,
<Route path="about?qs1=:qs&qs2=:qs2" component={About} />
从这个意义上说,查询参数不是路由的一部分。您需要在组件中检查它们,例如:
class About extends React.Component {
render() {
return(
<div>
{this.props.location.query.qs1 ? 'Correct route!' : 'Invalid route!'}
</div>
);
}
}
您还可以检查内部的查询参数componentDidMount并将您的用户重定向到不同的路由(例如 404)。在官方文档中阅读更多关于路由匹配的信息。