import { Injectable , Inject } from '@angular/core' ; import { CanActivate , CanLoad , Router , Route , ActivatedRouteSnapshot , RouterStateSnapshot } from '@angular/router' ; import { Observable } from 'rxjs/Observable' ; import 'rxjs/add/operator/map' ; import { Store } from '@ngrx/store' ; import { AppState } from '../domain/state' ; @ Injectable ( ) export class AuthGuardService implements CanActivate , CanLoad { constructor ( private router , private store$ ) { } canActivate ( route , state ) { const url = state . url ; return this . store$ . select ( appState => appState . auth ) . map ( auth => ! auth . hasError ) ; } canLoad ( route ) { let url = `/${ route . path }` ; return this . store$ . select ( appState => appState . auth ) . map ( auth => ! auth . hasError ) ; } }