import { Injectable } from '@angular/core' ; import { Router } from '@angular/router' ; import { Auth } from './auth' ; import { Observable } from 'rxjs/Observable' ; import "rxjs/add/operator/map" ; @ Injectable ( ) export class AuthGuard { constructor ( private router , private auth ) { } canActivate ( ) { return this . auth . check ( ) . map ( ( result ) => { if ( ! result ) { this . router . navigate ( [ '/' ] ) ; } return result ; } ) ; } }