docs(router): changes suggested by Deb Kurata in #1808
This commit is contained in:
parent
962b215048
commit
d1dd2b82f4
|
@ -1,20 +1,13 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CanActivate,
|
import { CanActivate, Router } from '@angular/router';
|
||||||
Router,
|
import { AuthService } from './auth.service';
|
||||||
ActivatedRouteSnapshot,
|
|
||||||
RouterStateSnapshot } from '@angular/router';
|
|
||||||
import { AuthService } from './auth.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
constructor(private authService: AuthService, private router: Router) {}
|
constructor(private authService: AuthService, private router: Router) {}
|
||||||
|
|
||||||
canActivate(
|
canActivate() {
|
||||||
// Not using but worth knowing about
|
|
||||||
next: ActivatedRouteSnapshot,
|
|
||||||
state: RouterStateSnapshot
|
|
||||||
) {
|
|
||||||
if (this.authService.isLoggedIn) { return true; }
|
if (this.authService.isLoggedIn) { return true; }
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1052,7 +1052,7 @@ h2#guards Route Guards
|
||||||
We'll examine other router guards in a future update to this chapter.
|
We'll examine other router guards in a future update to this chapter.
|
||||||
:marked
|
:marked
|
||||||
We can have multiple guards at every level of a routing hierarchy.
|
We can have multiple guards at every level of a routing hierarchy.
|
||||||
The router checks the `CanDeactive` guards first, from deepest child route to the top.
|
The router checks the `CanDeactivate` guards first, from deepest child route to the top.
|
||||||
Then it checks the `CanActivate` guards from the top down to the deepest child route.
|
Then it checks the `CanActivate` guards from the top down to the deepest child route.
|
||||||
If _any_ guard returns false, pending guards that have not completed will be canceled,
|
If _any_ guard returns false, pending guards that have not completed will be canceled,
|
||||||
and the entire navigation is canceled.
|
and the entire navigation is canceled.
|
||||||
|
|
Loading…
Reference in New Issue