简体   繁体   中英

Angular 6 - Resolver + Guard + ngrx

I use ngrx and i have a store that has a list of academies ['academy1', 'academy2']

I populate the store with a resolver.

Now I need to

canActivate(route: ActivatedRouteSnapshot, state_: RouterStateSnapshot): any {

  return this.store.pipe(select(state => state.user)).subscribe((user) => {
     return user.academies.includes(route.params.domain);
  });
}

But as I know... guards running before resolvers. So.... how can I check permissions with guards and ngrx?

On the first request, this can never work. You need to have a route which will populate the store before this guard would work if you are populating in a resolver.

If this data is required to work out if you can activate any route, then you need to populate the store on (for example) the result of a login action, before you attempt to navigate. Alternatively, have a default route which does not have this guard but populates the store, then navigate (if you do not have a login action).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM