[英]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.