在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中显示的角色 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- scala – spray-json和列表编组
- 请求的资源上不存在“Access-Control-Allow-Origin”标头.
- 一套不错的基于Bootstrap的博客系统静态页面
- 如何在Scala中初始化和“修改”循环持久数据结构?
- angularJS controller 控制器获取控制父级标签
- angularjs – ng-change on select选项调用多个唯一函数
- 常用的WebServices
- scala – 如何使用嵌套元组或HList处理Slick的“22”列表?
- angular – 为什么简单的[myHighlight] =“…”适用于属性指
- Kendo UI Angular 2中网格列名称的工具提示