Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
- import { Observable } from 'rxjs/Rx';
- import { MockAuthenticationService } from './authentication/authentication.service';
- @Injectable()
- export class AsynchronousGuard implements CanActivate {
- constructor(private router: Router, private auth: MockAuthenticationService) {}
- canActivate(route:ActivatedRouteSnapshot,
- state:RouterStateSnapshot):Observable<boolean>|boolean {
- this.auth.subscribe((authenticated) => {
- if (authenticated) {
- return true;
- }
- this.router.navigateByUrl('/login');
- return false;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement