import { Injectable } from '@angular/core'; import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router, UrlTree } from '@angular/router'; import { Observable } from 'rxjs'; import { AuthenticationService } from '../_services/authentication.service'; @Injectable({ providedIn: 'root' }) export class AuthGuard implements CanActivate { constructor(private _authService: AuthenticationService, private router: Router){} canActivate( next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { if (this._authService.IsLoggedIn){ return true; } else { return this.router.parseUrl('/home'); } } }