我有以下路线配置:
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中进行重定向,但虚拟路线无论如何都需要一个组件.
使用具有虚拟组件的虚拟路由,该组件仅根据角色重定向是可行的方法.您也可以在防护 https://angular.io/docs/ts/latest/guide/router.html#!#guards中进行重定向,但虚拟路线无论如何都需要一个组件.
您还可以使用router.resetConfig()来加载路由,具体取决于Dynamic routing based on external data中显示的角色