src/app/guards/auth.guard.ts
Methods |
constructor(router: Router, authService: AuthService)
|
|||||||||
Defined in src/app/guards/auth.guard.ts:6
|
|||||||||
Parameters :
|
canActivate |
canActivate()
|
Defined in src/app/guards/auth.guard.ts:9
|
Returns :
boolean
|
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { AuthService } from '../services/auth.service';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router, private authService: AuthService) {}
canActivate() {
if (this.authService.authenticated) {
return true;
}
this.router.navigate(['/login']);
return false;
}
}