import { Injectable } from '@angular/core' ; import { Router , CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot } from '@angular/router' ; import { AuthenticationService } from '@app/_services' ; @ 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' ] , { queryParams : { returnUrl : state . url } } ) ; return false ; } }