I'm trying to put access checks for routes and display access denied page instead of actual page. From the example below we can alert access denied on route click . I would prefer to navigate to the actual page and then show Access denied.
http://plnkr.co/edit/w1NCkGs0Tv5TjivYMdvt?p=preview
lets say url with access check is /admin/manageusers
and component name is ManageUserComponent
and if a user don't have access and tries the url, it should navigate to the route /admin/manageusers
but should be showing Access Denied in the page
.
1.One thing i can do is to use route resolve
feature and get the value related to users access and in ManageUserComponent
and switch the template. This approach will endup having similar code in multiple components associated with routes where i want to implement access logic.
- Let all
component
where access check needed extends anotherbase class
and validate above logic , if success then allow child component to proceed. Yet to figure out how to extend another class properly
Main goal is to preserve the accessed url with error message in the page. And the component functions should not execute.
If you can think of approaches and options to implement, please share.
If the description is not clear please let me know, i will try to make it better.
You can do something like this on the app-routing.module.ts
then define this LoggedInGuard service
Hope this may help you out.