import { Injectable } from '@angular/core' ; import { ActivatedRouteSnapshot , CanActivate , Router , RouterStateSnapshot } from '@angular/router' ; import { AuthenticationService } from './authentication.service' ; @ Injectable ( { providedIn : 'root' } ) export class AuthGuard implements CanActivate { constructor ( private router , private authenticationService ) { } canActivate ( route , state ) { const currentUser = this . authenticationService . currentUserValue ; if ( currentUser ) { return true ; } this . router . navigate ( [ '/login' ] ) ; return false ; } }