Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Created July 18, 2018 07:10
Show Gist options
  • Save brachi-wernick/3196e8fc31d291d15db2bdf61db6bde9 to your computer and use it in GitHub Desktop.
Save brachi-wernick/3196e8fc31d291d15db2bdf61db6bde9 to your computer and use it in GitHub Desktop.
can activate guard base on route data
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
if (route.component && route.data) {
let permissions = route.data.permissions;
if (permissions) {
return this.securityService.userHasPermissions(permissions)
.map(hasAccess => {
if (hasAccess) {
return true;
}
else {
this.router.navigate(['/unauthorized'], {replaceUrl: true})
}
})
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment