简体   繁体   中英

Angular route authorization & security

I am new to angular and I just learned about the routing mechanics and the routing guards to provide authorization to access routes. As a front end framework, this guard mechanic seems insufficient to me to secure my web server, unless I'm failing to understand something, as the restricted 'pages' (routes) are also downloaded during the first connection. What would be the best practice to protect, say, a /admin route ?

"The restricted pages are also downloaded during first connection". This is not true. Only if your guard interface return true the route will even be loaded.

You can use the CanActivate to check before resolving route.

Example from here :

import { Injectable }     from '@angular/core';
import { CanActivate }    from '@angular/router';

@Injectable()
export class AuthGuard implements CanActivate {
  canActivate() {
    console.log('AuthGuard#canActivate called');
    return true;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM