【发布时间】:2019-09-22 15:02:15
【问题描述】:
我正在 React-router-dom (v5.0.1) 中设置嵌套路由,但是当我尝试访问其中一个嵌套路由时,它(路由 /primary/:id)无法正常工作。
嵌套路由看起来像..
const id = ({match}) => (
<div>
with id {match.params.id}
</div>
)
const primary = ({match}) => (
<div>
This is the Primary route
<br/>
<Link to='/primary/one'>Primary with id</Link>
<Route path='/primary/:id' component={id} />
</div>
)
我无法访问 id 组件。 我在 Routes 组件中调用主要组件。
const Routes = () => {
return(
<Router>
<Route exact path='/' component={main} />
<Route exact path='/primary' component={primary} />
</Router>
)
}
Routes在App组件中调用如下。
function App() {
return (
<div className="App">
<Routes />
</div>
);
}
【问题讨论】: