我的路线设置如下:
<Route path="/chat/:id" component={Chat} />
<Route path="/chat/new" component={NewChat} />
当我转到 chat/new
时,它还会显示 {Chat}
。当我转到 /chat/new
时,有什么方法可以专门调用 NewChat
吗?
最佳答案
您可以使用Switch
并重新排序您的路线,因为Switch
渲染第一个匹配的Route
<Switch>
<Route path="/chat/new" component={NewChat} />
<Route path="/chat/:id" component={Chat} />
</Switch>
关于reactjs - 具有相似路径(固定和动态路径参数)的 React Router v4 组件为 "overlapping",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47946003/