import { Injectable } from "@angular/core" ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot } from "@angular/router" ; import { Observable } from "rxjs/Observable" ; import { Router } from "@angular/router" ; import { AuthService } from "../services/auth.service" ; @ Injectable ( ) export class AuthGuard implements CanActivate { constructor ( private readonly authService , private readonly router ) { } canActivate ( next , state ) { const isLoggedIn = this . authService . isLoggedIn ( ) ; console . log ( "canActivate" , isLoggedIn ) ; if ( isLoggedIn === false ) { this . router . navigate ( [ "/login" ] ) ; return false ; } return isLoggedIn ; } }