Reputation: 799
I am building a user-list component to list all users and user-detail components to show an individual user.
However, only the admin should be able to see all users, and a user can only see their own profile.
{
path: 'users'... some can activate guard here that checks admin role?
},
{
path: 'users/:id'...
}
I guess my question is, is this the right approach since the details route is a child of users, and only admins can see that route or is there a better pattern?
Upvotes: 0
Views: 255
Reputation: 3858
Angular provides several guards to do this. You can use canActivate
as illustrated in CanActivate: requiring authentication or canLoad
as illustrated in CanLoad Guard: guarding unauthorized loading of feature modules. Implement your conditional logic in one of them.
Upvotes: 1