Moved all heroes functionality into milestone 2 Crisis Center initial functionality is milestone 3 Admin feature module as milestone 4 including route guard examples Updated milestone 5 to lazy load admin feature module Added examples for CanLoad, CanActivateChildren guard, component-less routes Added section on explanation of ActivatedRoute Added section on animating route components Added section on relative navigation
		
			
				
	
	
		
			38 lines
		
	
	
		
			980 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			980 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| // #docregion
 | |
| import { Injectable }       from '@angular/core';
 | |
| import {
 | |
|   CanActivate, Router,
 | |
|   ActivatedRouteSnapshot,
 | |
|   RouterStateSnapshot
 | |
| }                           from '@angular/router';
 | |
| import { AuthService }      from './auth.service';
 | |
| 
 | |
| @Injectable()
 | |
| export class AuthGuard implements CanActivate {
 | |
|   constructor(private authService: AuthService, private router: Router) {}
 | |
| 
 | |
|   canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
 | |
|     let url: string = state.url;
 | |
| 
 | |
|     return this.checkLogin(url);
 | |
|   }
 | |
| 
 | |
|   checkLogin(url: string): boolean {
 | |
|     if (this.authService.isLoggedIn) { return true; }
 | |
| 
 | |
|     // Store the attempted URL for redirecting
 | |
|     this.authService.redirectUrl = url;
 | |
| 
 | |
|     // Navigate to the login page with extras
 | |
|     this.router.navigate(['/login']);
 | |
|     return false;
 | |
|   }
 | |
| }
 | |
| // #enddocregion
 | |
| 
 | |
| /*
 | |
| // #docregion can-load-interface
 | |
| export class AuthGuard implements CanActivate, CanLoad {
 | |
| // #enddocregion can-load-interface
 | |
| */
 |