7
Helloo,Angular2限制所有路線
我創建了一個後衛:
import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router) {
}
canActivate() {
if (localStorage.getItem('currentUser')) {
// logged in so return true
return true;
}
// not logged in so redirect to login page
this.router.navigate(['/login']);
return false;
}
}
,並與他們內部的多個路由多個模塊。如何輕鬆地限制我的應用程序中的每個路線與這個警衛?
問候