[英]React Router 4 Nested Routes Clashing
我有以下路线:
<Switch>
<Route path='/:profileType/:profileId' component={Profile}/>
<Route path='/about/:aboutThing' component={AboutThing}/>
</Switch>
当我尝试转到/about/:aboutThing
-它被认为是{Profile}
路线。 从技术上来说,这是有道理的:profileType
可以是任何字符串,因此任何嵌套路由都将被识别为Profile
。
我想知道是否可以在不更改其路线的情况下渲染{AboutThing}
。 从技术上讲, /about
应该是该路由的保留字。 我试着做:
<Route exact path='/about/:aboutThing' component={AboutThing}/>
但这也不起作用。 尝试不必在该路径中添加额外的字符串以使其工作。 有什么想法/想法吗?
答案很简单, Switch
在第一个匹配的路线后停止,因此您可以像
<Switch>
<Route path='/about/:aboutThing' component={AboutThing}/>
<Route path='/:profileType/:profileId' component={Profile}/>
</Switch>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.