重定向到 Angular 2 中第一个允许的路由?
Redirect to first allowed route in 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',只有域管理页面,虽然每个授权用户都至少可以访问其中一个,但其中 none 对所有人都可用用户。
是否有一个选项说:重定向到第一条路线,可以激活?或者我需要在路径“/”下编写一个虚拟组件,它会根据用户角色进行动态重定向?
三是无法重定向到第一条可用路由。
使用带有虚拟组件的虚拟路由,根据角色进行重定向是可行的方法。您也可以在守卫 https://angular.io/docs/ts/latest/guide/router.html#!#guards 中进行重定向,但虚拟路由无论如何都需要一个组件。
您还可以使用 router.resetConfig()
根据
中所示的角色加载路由
我有以下路由配置:
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',只有域管理页面,虽然每个授权用户都至少可以访问其中一个,但其中 none 对所有人都可用用户。
是否有一个选项说:重定向到第一条路线,可以激活?或者我需要在路径“/”下编写一个虚拟组件,它会根据用户角色进行动态重定向?
三是无法重定向到第一条可用路由。 使用带有虚拟组件的虚拟路由,根据角色进行重定向是可行的方法。您也可以在守卫 https://angular.io/docs/ts/latest/guide/router.html#!#guards 中进行重定向,但虚拟路由无论如何都需要一个组件。
您还可以使用 router.resetConfig()
根据