Reputation: 49
I am currently trying to create a page with a different template. The template depends on the permissions of the user that wants to access the route. If its an admin (I can check the user status) I want to display the full component (which is still under construction and not final). But if its a normal user then i have a placeholder template just displaying something like "This page will be open on 01.01.XXXX". Whats the best way to implement such a behaviour? Is it necessary to have 2 different components and checking the user status when routing to the page?
Upvotes: 0
Views: 531
Reputation: 650
Deciding what to show depending on roles is usually done with one component and *ngIf
statements. I recommend creating a pipe which takes an array of allowed roles and returns a boolean
as a result to (not)show something.
But that really depends on your use case and what is the content of your page.
However, for the pages that are only users with certain roles allowed to see, it is necessary to implement AuthGuard
and protect the route that way. So, in your case, if the user is a 'normal' user, he/she probably should not be able to access the page.
Upvotes: 1