我的警卫让我回到空白页而不是重定向我。我的root也不是一个空白页面,它也应该发送给我登录。当我转到任何supervisor
页面时会发生这种情况。
这些是我的路线:
export const appRoutes: Routes = [
{path: '', component: LoginScreenComponent},
{path: 'login', component: LoginScreenComponent},
{path: 'student', component: StudentDownloadComponent, canActivate: [StudentGuard]},
{path: 'student/download', component: StudentDownloadComponent, canActivate: [StudentGuard]},
{path: 'student/upload', component: StudentUploadComponent, canActivate: [StudentGuard]},
{path: 'supervisor', component: SupervisorUploadComponent, canActivate: [SupervisorGuard]},
{path: 'supervisor/upload', component: SupervisorUploadComponent, canActivate: [SupervisorGuard]},
{path: 'supervisor/logs', component: SupervisorLogsComponent, canActivate: [SupervisorGuard]},
{path: 'supervisor/overzicht', component: SupervisorOverzichtComponent, canActivate: [SupervisorGuard]}
];
这是我的后卫:
@Injectable()
export class SupervisorGuard implements CanActivate {
constructor(private supervisor: AuthService, private router: Router) {}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
if (this.supervisor.getSupervisorLoggedIn()) {
return true;
} else {
this.router.navigate(['/login']);
return false;
}
}
}
服务:
@Injectable()
export class AuthService {
private isStudentLoggedIn;
private isSupervisorLoggedIn;
constructor() {
this.isStudentLoggedIn = false;
this.isSupervisorLoggedIn = false;
}
setStudentLoggedIn() {
this.isStudentLoggedIn = true;
}
getStudentLoggedIn() {
return this.isStudentLoggedIn();
}
setSupervisorLoggedIn() {
this.isSupervisorLoggedIn = true;
}
getSupervisorLoggedIn() {
return this.isSupervisorLoggedIn();
}
}
答案 0 :(得分:3)
在服务中,你试图调用isSupervisorLoggedIn
就好像它是一个函数,但它只是一个布尔值。
您应该return this.isSupervisorLoggedIn;
而不是