q2-angular-routeguard
v0.0.3
Published
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.11.
Downloads
4
Readme
Q2AngularRouteguard
This library was generated with Angular CLI version 9.1.11.
How to use
To use the Q2 Route Guard for Angular projects, simply install it and import it into your app guard. It has two functions, CanActivate and CanActivateChild, just like the built in functions of the app guard to minimize confusion. The Q2AngularRouteguardService CanActivate function takes ActivatedRouteSnapshot, RouterStateSnapshot (both built in properties you can get from @angular/router), and an array of the CanActivateRoutes from your app settings for the portal.
Similarly, CanActivateChild takes RouterStateSnapshot and an array of AuthorizedNavs.
Example usage
@Injectable({
providedIn: 'root'
})
export class RouteGuard implements CanActivate, CanActivateChild {
userData: any;
authorizedNavs: any;
canActivateRoutes: any;
constructor(private appService: AppService, private q2RouteGuard: Q2AngularRouteguardService) {
this.canActivateRoutes = this.appService.getAppData().canActivateRoutes;
this.authorizedNavs = this.appService.getAppData().authorizedNavs;
}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot) {
return this.q2RouteGuard.canActivate(next, state, this.canActivateRoutes);
}
canActivateChild (next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this.q2RouteGuard.canActivateChild(state, this.authorizedNavs);
}
}