Helloo,
我创建了一个守卫:
import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router) {
}
canActivate() {
if (localStorage.getItem('currentUser')) {
// logged in so return true
return true;
}
// not logged in so redirect to login page
this.router.navigate(['/login']);
return false;
}
}
并有多个模块,其中有多个路由。如何使用此防护轻松限制应用程序中的每条路线?
此致
与警卫一起设置一条空路线,然后完成其余路线children
其中:
RouterModule.forRoot([
{ path: '', canActivate: [AuthGuard], children: [...restOfYourRoutes] }])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)