My workaround:
auth.service.ts
import { Injectable, Injector } from '@angular/core';
import { ActivatedRoute, Router, RouterStateSnapshot } from '@angular/router';
@Injectable()
export class AuthService {
constructor(private route: ActivatedRoute,
private router: Router,
private injector: Injector) {
this.forceRunAuthGuard();
}
private forceRunAuthGuard() {
if (this.route.root.children.length) {
const curr_route = this.route.root.children[ '0' ];
const AuthGuard = curr_route.snapshot.routeConfig.canActivate[ '0' ];
const authGuard = this.injector.get(AuthGuard);
const routerStateSnapshot: RouterStateSnapshot = Object.assign({}, curr_route.snapshot, { url: this.router.url });
authGuard.canActivate(curr_route.snapshot, routerStateSnapshot);
}
}
}
app.routes.ts
{ path: 'faq', canActivate: [ AuthGuard ], component: FaqComponent },
{ path: 'about', canActivate: [ AuthGuard ], component: AboutUsComponent },
{ path: 'upgrade', canActivate: [ AuthGuard ], component: UpgradeComponent },
This code runs again AuthGuard.
source
share