import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot } from '@angular/router' ; import { Observable } from 'rxjs' ; import { AuthService } from '../services/auth.service' ; import { Router } from '@angular/router' ; @ Injectable ( { providedIn : 'root' } ) @ Injectable ( ) export class AuthGuard implements CanActivate { constructor ( private authService , private router ) { } canActivate ( next , state ) { if ( this . authService . authenticated ) { return true ; } else { this . router . navigate ( [ '/' ] ) ; return false ; } } }