当我在路由中使用子项时,我无法从登录页面导航到仪表板页面,如下所示:
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 }
];
然而,当我从路由中删除子属性并使其兄弟姐妹路由工作正常。制作儿童路线时有什么问题?我正在使用cli 1.6.0-rc.1
到目前为止我尝试了什么?
评论AuthGuard不起作用所以问题不在于那部分
我已经确认只有当我将它们作为子路径(我需要制作面包屑)时才会出现此问题。如果所有路由都是兄弟,则路由正常工作
在{enableTracing:true}
RouterModule.forRoot
使用了NavigationStart(id: 4, url: '/dashboard')
,我找到了html, body {
font-family: "Trebuchet MS", sans-serif;
margin: 50px;
background: url("clouds.png");
}
,这对DashboardComponent来说是正确的网址
在SO上搜索了类似的标题,但没有一个问题解决过同样的问题:
Angular 2.0.1 Router EmptyError: no elements in sequence
Angular2 routing issues - Zone aware error No elements in sequence
答案 0 :(得分:13)
此错误是由Angular的最新版本路由器引起的。 请删除还原角度版本或添加pathMatch:'完整'到你的路线。
export const userRoutes = [
{ path: 'profile', component: ProfileComponent, pathMatch: 'full' },
{ path: 'login', component: LoginComponent, pathMatch: 'full' }
];
export const appRoutes = [
{ path: '', redirectTo: '/events', pathMatch: 'full' },
{ path: 'user', loadChildren: './user/user.module#UserModule' }
];
您可以找到问题here