Navigating Inwards Guard Inwards Angular5

There are unopen to cases when nosotros require to navigate inwards a Guard rather than inwards component. Why? Well, patently yous didn't convey to define a constituent where yous require to navigate. An representative occupation instance would endure a road where yous require to navigate given a for sure role.

H5N1 sample route:
 {  path: 'bride',  canLoad: [AuthGuard],  loadChildren: 'app/module/bride/bride.module#BrideModule' } 
H5N1 matching guard that navigates defending on role:
 @Injectable() export course of report AuthGuard implements CanActivate {      constructor( mortal router: Router, mortal route: ActivatedRoute ) {      }      canActivate( next: ActivatedRouteSnapshot, state: RouterStateSnapshot ): Observable | Promise | boolean {         console.log( 'registration.guard' )          if ( !KeycloakService.auth.loggedIn || !KeycloakService.auth.authz.authenticated ) {             furnish false;         }          //check grouping         if ( KeycloakService.hasGroup( 'Anime' ) ) {             this.router.navigate( ['/bride/postRegistration'] );          } else if ( KeycloakService.hasGroup( 'Vendor' ) ) {             this.router.navigate( ['/bride/postRegistration'] );         }          furnish true;     } } 
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.