[英]Setting priority in order of paths with react-router
My routing looks like this 我的路线看起来像这样
<Route path="account" component={Page1}>
<Route path="new" component={Page2}/>
<Route path="(:userId)" component={Page1}/>
</Route>
Whenever I go to account/new
it defaults to the (:userId)
path and directs me to Page1
treating 'new' as the optional parameter. 每当我进入
account/new
它默认使用(:userId)
路径,并引导我进入Page1
将“新建”作为可选参数。 How can I make it default to Page2
? 如何使其默认为
Page2
?
I am using V3 of react-router
我正在使用V3的
react-router
It is going to Page1
because account needs to be an exact path. 由于帐户必须是确切路径,因此将转到
Page1
。 Since it isn't, when you go to account/new
it will show the component for account
. 由于不是,因此当您转到
account/new
,它将显示account
的组件。 Try this: 尝试这个:
<Route exact path="/account" component={Page1}>
<Route path="/new" component={Page2}/>
<Route path="/(:userId)" component={Page1}/>
</Route>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.