【问题标题】:Angular 5 EmptyError: no elements in sequence while making child routesAngular 5 EmptyError:制作子路由时没有元素顺序
【发布时间】: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

到目前为止我尝试了什么?

  1. 评论 AuthGuard 不起作用,所以问题不在于那部分

  2. 我已经验证,只有当我将它们作为子路由(我需要它来制作面包屑)时才会出现此问题。如果所有路由都是兄弟,则路由正常

  3. RouterModule.forRoot 中使用了{enableTracing:true},在那里我找到了NavigationStart(id: 4, url: '/dashboard'),这似乎是DashboardComponent 的正确url

  4. 在 SO 上搜索类似标题的问题,但没有人解决相同的问题:

Angular 2.0.1 Router EmptyError: no elements in sequence

Angular2 routing issues - Zone aware error No elements in sequence

Angular 2.0.1 Router EmptyError: no elements in sequence

【问题讨论】:

  • 如果你的rxjs是“^5.5.2”,你试试改成“5.5.2”。
  • 进行此更改后,我收到一条错误消息“无法读取未定义的属性 'loadChildren'”

标签: angular routing


【解决方案1】:

这个错误是由于 Angular 路由器的最新版本造成的。 请删除 revert back angular 版本或将 pathMatch: 'full' 添加到您的路线。

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

【讨论】:

  • 我已经在我在问题中发布的代码中的路线中使用了 pathMatch: 'full' 但它仍然给出了同样的错误。
  • 您提供的链接表明问题发生在 RxJs 5.5.3 上,但我在签入 package.json 文件时使用的是 RxJs 5.5.2
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-10
  • 2019-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多