CanActivate
The
canActivate
guard is the default mechanism of adding permissions to the application. To see how we can use it, let's take the example from preceding code and remove lazy loading:
const ROUTES = [ { path: ':folder', children: [ { path: '', component: ConversationsCmp }, { path: ':id', component: ConversationCmp, children: [...] } ] }, { path: 'contacts', canActivate: [CanActivateContacts], children: [ { path: '', component: ContactsCmp }, { path: ':id', component: ContactCmp } ] } ];
Where
CanActivateContacts
is defined as shown in the following code:
@Injectable() class CanActivateContacts implements CanActivate { constructor(private permissions: Permissions, private currentUser: UserToken) ...