import { Injectable } from '@angular/core' ; import { CanActivate , Router } from '@angular/router' ; import { Observable } from 'rxjs' ; import { ApiService } from './api.service' ; @ Injectable ( { providedIn : 'root' } ) export class AuthguardGuard implements CanActivate { constructor ( private auth , private router ) { } canActivate ( ) { if ( ! this . auth . isAuthenticated ) { this . router . navigate ( [ '/login' ] ) ; return false ; } return true ; } }