import { HardcodedAuthenticationService } from './hardcoded-authentication.service' ; import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot , Router } from '@angular/router' ; @ Injectable ( { providedIn : 'root' } ) export class RouteGuardService implements CanActivate { constructor ( private hardcodedAuthenticationService , private router ) { } canActivate ( route , state ) { if ( this . hardcodedAuthenticationService . isUserLoggedIn ( ) ) return true ; this . router . navigate ( [ 'login' ] ) ; return false ; } }