I have a route setup like this:
export const APP_ROUTES: Routes = [ { path: '', resolve: { user: CurrentUserResolver }, children: [ { path: ':sectionKey', canActivate: [SectionAccessGuard], children: [ { path: 'dashboard', component: DashboardComponent } ] } ] } ]
If the parent route will retrieve the user through an HTTP call, and I want my sub-route :sectionKey activated only if the current user has access to it. The problem is that my canActivate SectionAccessGuard seems to SectionAccessGuard called before the snapshot is full:
@Injectable() export default class SectionAccessGuard implements CanActivate { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { console.log(route.data); console.log(route); return true; } }
In the console, the first entry will have nothing; however, in the 2nd entry, the user field will be populated.
I know that the canActivate method canActivate also return an Observable<boolean> , but I donβt see any bindings on how to wait for the solution to complete.
What am I missing here? I feel it should be pretty straight forward. I am currently using angular v4.0.0-rc.2
angular
John
source share