【发布时间】:2018-05-16 19:42:20
【问题描述】:
当我使用子路由时,我无法从登录页面导航到仪表板页面,如下所示:
const appRoutes: Routes = [
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent,pathMatch: 'full' },
{
path: 'dashboard',pathMatch: 'full', /* canActivate: [AuthGuard], */ component: DashboardComponent ,
children: [
{
path: 'online-submission/:moduleName',pathMatch: 'full', component: OnlineSubmissionComponent,
/* canActivate: [AuthGuard], */data:{
breadcrumb: "online-submission"
} ,
children: [
{ path: 'batch-upload-members',pathMatch: 'full', component: BatchUploadMembersComponent,
/* canActivate: [AuthGuard], */data:{
breadcrumb: "batch-upload-members"
} },
{ path: 'select-members',pathMatch: 'full', component: SelectMembersComponent,
/* canActivate: [AuthGuard], */data:{
breadcrumb: "select-members"
}
}
]
}
]
},
{ path: '**', component: PageNotFoundComponent }
];
但是,当我从路由中删除 children 属性并使它们成为兄弟姐妹时,路由工作正常。当我制作子路线时有什么问题?我正在使用 cli 1.6.0-rc.1
到目前为止我尝试了什么?
评论 AuthGuard 不起作用,所以问题不在于那部分
我已经验证,只有当我将它们作为子路由(我需要它来制作面包屑)时才会出现此问题。如果所有路由都是兄弟,则路由正常
在
RouterModule.forRoot中使用了{enableTracing:true},在那里我找到了NavigationStart(id: 4, url: '/dashboard'),这似乎是DashboardComponent 的正确url在 SO 上搜索类似标题的问题,但没有人解决相同的问题:
Angular 2.0.1 Router EmptyError: no elements in sequence
Angular2 routing issues - Zone aware error No elements in sequence
【问题讨论】:
-
如果你的rxjs是“^5.5.2”,你试试改成“5.5.2”。
-
进行此更改后,我收到一条错误消息“无法读取未定义的属性 'loadChildren'”