假设我已经使用路径'/ some / childr'定义了顶级路由:
[{ path: '/some/childr'}]
然后我有另一个带有子路由/some
的顶级路由/childr
:
[{ path: '/some', children: ['/childr']}]
基本上他们都应该对/some/childr
做出反应。现在我在浏览器中导航到/some/childr
,哪条路线优先?
答案 0 :(得分:3)
根据documentation,路由器选择首次匹配获胜策略的路线。
因此,如果您定义了以下路线,那么它将首先与/some/childr
路线匹配并加载MyComponent
。
[
{ path: '/some/childr', component: MyComponent},
{
path: '/some',
children: [
{
path: '/childr', component: ChildComponent
}
]
}
]
如果您已定义如下路线,则会加载ChildComponent
。
[
{
path: '/some',
children: [
{
path: '/childr', component: ChildComponent
}
]
},
{ path: '/some/childr', component: MyComponent}
]