Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created July 31, 2019 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/d56da6607dd455cfa766b7ee97cdfb43 to your computer and use it in GitHub Desktop.
Save NetanelBasal/d56da6607dd455cfa766b7ee97cdfb43 to your computer and use it in GitHub Desktop.
@Injectable({ providedIn: 'root' })
export class FeatureFlagGuard implements CanActivate {
constructor(private userQuery: UserQuery) {
}
canActivate(route: ActivatedRouteSnapshot): boolean {
return this.userQuery.hasFlags(route.data.flags);
}
}
const routes: Routes = [
...
{
path: '...',
component: ProtectedComponent,
canActivate: [FeatureFlagGuard],
data: {
flags: 'b' // or ['a', 'b']
}
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment