【发布时间】:2018-06-01 06:10:10
【问题描述】:
我想在 Angular 6 中定义多级路线,这是我需要的:
对于一级路线,我有:
dashboardRoutes:Routes=[
{
path: "dashboard",
component: DashobardComponent,
canActivate: [AuthGuard],
children:[
{
path: 'user', component: UserComponent,
},
{
path: 'overview', component:OverViewComponent
}
]
}
];
但现在,我想拥有自己的孩子,所以我将 html 定义为:
<div>This is overvew</div>
<router-outlet></router-outlet>
然后我定义了如下概览路线:
const overviewRoutes:Routes = [
{
path: "",
component: OverViewComponent,
children:[
{
path:'reg',
component: RegularComponent
},
{
path:'rt',
component: RealTimeComponent
}
]
}
];
然后我得到了错误:
Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'dashboard/overview/reg'
现在,我迷路了,overView 已经定义在第二条路由中,我应该如何在此处更新第一条路由?
我把第一个改成
路径:'overview',redirectTo:'overview/reg',完全失败。
我可以在第一个路由定义中定义所有路由,但这根本不够优雅。我想要在它自己的模块中的概览路由定义。
希望你明白我的意思。
谢谢
【问题讨论】:
标签: angular angular-router angular6