小编my *_*est的帖子

基于角色的角度路由

我正在使用 Angular,这是用于我的身份验证检查:

export class EnsureAuthenticated implements CanActivate {
    constructor(private auth: AuthService, private router: Router) {}
    canActivate(): boolean {
        if (localStorage.getItem('token')) {
            return true;
        }
        else {
            this.router.navigateByUrl('/login');
            return false;
        }
    }
}    

{ 
    path: 'path', 
    component: myComponent,
    canActivate: [EnsureAuthenticated]
}
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我的问题是用户和管理员都可以访问此页面。

我知道我没有设置任何条件。如何在其上设置适当的条件?

我不想让管理员访问此页面

angular2-routing angular

2
推荐指数
1
解决办法
3753
查看次数

标签 统计

angular ×1

angular2-routing ×1