假设 Return false 将在 http 调用上的身份验证中返回,但现在我从 CanLoadChildren() 方法返回 false 以测试 canLoad 但是尽管调用 canLoad 并返回 false canLoad 仍然加载模块并重定向到该模块。任何人都可以帮助? 谢谢
身份验证服务
import {
Injectable
} from '@angular/core';
@Injectable()
export class AuthService {
constructor() {}
public CanLoadChildren(): boolean {
return false;
}
}
验证保护文件
import {
AuthService
} from './auth.service';
import {
Injectable
} from '@angular/core';
import {
CanActivate,
CanLoad,
Route,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Router
} from '@angular/router';
@Injectable()
export class CanActivateViaAuthGuardService implements CanActivate, CanLoad {
constructor(private _authService: AuthService, private router: Router) {}
canLoad(route: Route): boolean {
console.log("Can Load Childrens Called");
console.log(route);
this.router.navigate(['/Domains']);
return this._authService.CanLoadChildren();
}
}
app.router.ts
export const APPROUTES: Routes = [
{
path: 'User',
canLoad: [CanActivateViaAuthGuardService],
loadChildren: 'app/LazyAdminConsoleModule'
}
]