0.0.3 • Published 4 years ago

q2-angular-routeguard v0.0.3

Weekly downloads
12
License
-
Repository
-
Last release
4 years ago

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);
    }
}
0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago