Created
November 6, 2018 12:47
-
-
Save raberana/cc266af4c6928bfa99de1fae35d6e1a2 to your computer and use it in GitHub Desktop.
Pre-loading user-specific routes in Angular: GIST App initializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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