在Angular 2中重定向到第一个允许的路由?

前端之家收集整理的这篇文章主要介绍了在Angular 2中重定向到第一个允许的路由?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下路线配置:

const routes: Routes = [
  { path: '',redirectTo: 'customers',pathMatch: 'full' },{ path: 'customers',component: CustomerListComponent,canActivate: [CustomerGuard] },{ path: 'products',component: ProductListComponent,canActivate: [ProductGuard] },{ path: 'sales',component: SalesListComponent,canActivate: [SalesGuard] }
];

问题是,我没有’dashbord’,只有域名管理页面,虽然每个授权用户都可以访问至少其中一个,但并不是所有用户都可以访问它们.

有没有选项可以说:重定向到第一条路线,可以激活吗?或者我需要在路径’/’下编写一个虚拟组件,根据用户角色进行动态重定向

解决方法

三无法重定向到第一条可用路线.
使用具有虚拟组件的虚拟路由,该组件仅根据角色重定向是可行的方法.您也可以在防护 https://angular.io/docs/ts/latest/guide/router.html#!#guards中进行重定向,但虚拟路线无论如何都需要一个组件.

您还可以使用router.resetConfig()来加载路由,具体取决于Dynamic routing based on external data显示的角色

猜你在找的Angularjs相关文章