在我的React应用中,我已经按照如下方式设置了路由:
class App extends Component {
render() {
return (
<div className="app">
<Header />
<Route exact path="/" component={PostList} />
<Route exact path="/:category" component={PostList} />
<Route exact path="/:category/:postid" component={PostDetails} />
</div>
);
}
}
/
和foo
很好地渲染了PostList
组件。 但是,当我尝试使用例如/foo/bar
到达PostDetails
组件时,它没有被匹配到。
我尝试调整路由定义的顺序以及使用exact
属性,但都没有成功。 没有收到任何错误消息,devtools中的检查器只是没有显示组件应该在的位置的任何输出。
我错过了什么? 我正在使用react-router-dom@4.2.2。
Switch
组件,但没有任何区别。我在浏览器中访问了此 URLhttp://localhost:3000/foo/bar
。我没有使用 BrowserRouter(也许我应该使用吗?) - Hinrichhttp://localhost:3000/#/foo/bar
。 - Shubham Khatri