Angular 2:router.navigate在if条件下无法正常工作

时间:2018-04-13 05:37:38

标签: angular routing navigation

Angular 2:我想根据if条件重定向到“inventory”组件。在执行router.navigate到“inventory”组件时,它会被重定向到默认组件,即仪表板 但我尝试重定向到外部url而不是正常工作。所以逻辑是正确的。以下是代码:

if(!(isStockManager()))
{
    this.router.navigate(['/inventory']);
    //document.location.href = 'https://stackoverflow.com';
}
else if(!(isWaiter()))
{
    this.router.navigate(['/waiter']);
}
else{
     this.router.navigate(['/dashboard'])
}

这是我的pages.routing:

  { path: '', redirectTo: 'dashboard', pathMatch: 'full',resolve: {data: LoginResolveService}},
  { path: 'dashboard', loadChildren: './dashboard/dashboard.module#DashboardModule',resolve: {data: LoginResolveService}},
  { path: 'waiter', redirectTo: 'waiter/table-list',resolve: {data: LoginResolveService}},
  { path: 'waiter', loadChildren: './waiter/waiter.module#WaiterModule',resolve: {data: LoginResolveService}},
  { path: 'inventory', loadChildren: './inventory/inventory.module#InventoryModule',resolve: {data: LoginResolveService}},
  { path: 'inventory', redirectTo: 'inventory/inventory',resolve: {data: LoginResolveService}}

0 个答案:

没有答案