import { Injectable } from '@angular/core'; import {ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, CanActivateChild, Router} from '@angular/router'; import { Observable } from 'rxjs'; import {AuthService} from './services/auth/auth.service'; @Injectable({ providedIn: 'root' }) export class AuthGuard implements CanActivateChild { constructor(private authService: AuthService, private router: Router) { } canActivateChild( childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { if(!this.authService.getLogged()){ this.router.navigate(['login']); return false; } return true; } }