import { Injectable } from '@angular/core' ; import { CanActivate , RouterStateSnapshot , Router , ActivatedRouteSnapshot } from '@angular/router' ; import { AuthService } from './auth.service' ; @ Injectable ( ) export class AuthguardService implements CanActivate { constructor ( private router , private authservice ) { } canActivate ( next , state ) { if ( this . authservice . authUser ( ) ) return true ; else { console . log ( 'You must be logged in' ) ; this . router . navigate ( [ 'login' ] ) ; return false ; } } }