1 import { Injectable } from '@angular/core';
2 import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
3 import { Observable } from 'rxjs';
5 import { AuthenticationService } from './../_services/authentication.service';
10 export class AuthGuard implements CanActivate {
13 private router: Router,
14 private authenticationService: AuthenticationService
18 next: ActivatedRouteSnapshot,
19 state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
20 const currentUser = this.authenticationService.currentUserValue;
22 // authorised so return true
26 // not logged in so redirect to login page
28 this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });