import { Injectable } from '@angular/core'; import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; import { AuthenticationService } from '../services/authentication.service'; @Injectable() export class AuthUserGuardService implements CanActivate { constructor(private _router: Router, private auth: AuthenticationService) { } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { if (!this.auth.userValue) { this._router.navigate(['home']); return false; } return true; } }