伙计们,我正试着让一个守卫守卫那些未经认证的人无法进入的路线。在我导入的AuthService中,可以像这样激活:
import { CanActivate, ActivatedRouteSnapshot } from '@angular/router';我还在出口中使用了这样的工具:
export class AuthService implements CanActivate {我创建了这样的canActivate方法:
canActivate(route: ActivatedRouteSnapshot): boolean {
if(!this.isAuthenticated()){
this.logout();
return false;
}
return true;
}但是,当我尝试在app-routing.module中的const路由中使用它时,它会抛出一个错误,说明它找不到名称'canActivate‘(我删除导入只是为了节省一些空间)。
canActivate: [AuthService],
children: [
{
path: 'dashboard',
loadChildren: () => import() },
{
path: '',
loadChildren: () => import() },
{
path: 'modules',
loadChildren: () => import() },
{
path: 'settings',
loadChildren: () => import() }
]我得到的错误是“找不到名字'canActivate'”和“找不到名字‘子”。有人知道这可能是什么原因吗?
发布于 2022-04-06 14:27:16
伙计们,我把一些东西放错了地方,这就是为什么它会抛出错误,谢谢你的评论:)
https://stackoverflow.com/questions/71768313
复制相似问题