Skip to content

Instantly share code, notes, and snippets.

@raberana
Created November 6, 2018 12:47
Show Gist options
  • Save raberana/cc266af4c6928bfa99de1fae35d6e1a2 to your computer and use it in GitHub Desktop.
Save raberana/cc266af4c6928bfa99de1fae35d6e1a2 to your computer and use it in GitHub Desktop.
Pre-loading user-specific routes in Angular: GIST App initializer
export function onAppInit(injector: Injector): () => Promise<any> {
return (): Promise<any> => {
return new Promise((resolve, reject) => {
let router = injector.get(Router);
console.log('**** INITIAL ROUTES ****');
console.log(router.config);
// Do whatever you want to get your user's permissions and then use only the routes that the user should have an access to
// In here, I am hard coding that the user should have no access to the admin page
let userPermittedRoutes = router.config.filter(i => i.path != 'admin');
router.resetConfig(userPermittedRoutes); // New routes without the admin
console.log('**** FILTERED ROUTES ****');
console.log(router.config);
resolve();
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment