【发布时间】:2019-01-20 01:35:52
【问题描述】:
目前我有以下代码:
<Router history={history}>
<div>
<Route exact path="/:id?" component={Container1} />
<Route path="/component2/ component={Container2} />
</div>
</Router>
"localhost:3000" 返回容器 1(如预期)。
"localhost:3000/123" 返回容器 1 的不同视图(如预期的那样)。
但是,当我导航到“localhost:3000/component2/”时,它会出现在组件 1 旁边。
我的问题是如何让索引路由同时接受一个 id 但仍然接受一个组件?
【问题讨论】:
标签: javascript reactjs path routes react-router