在 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)。 Read more about Route Matching in the official docs .
关于reactjs - React Router 3,与查询参数完全匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41334284/