加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:08:24 所属栏目:安全 来源:网络整理
导读:我有以下路线配置: const routes: Routes = [ { path: '',redirectTo: 'customers',pathMatch: 'full' },{ path: 'customers',component: CustomerListComponent,canActivate: [CustomerGuard] },{ path: 'products',component: ProductListComponent,canAc
我有以下路线配置:

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中显示的角色

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读