CanActivateChild
The canActivateChild
guard is similar to canActivate
, except that it is called when a child of the route is activated, and not the route itself.
Imagine a function that takes a URL and decides if the current user should be able to navigate to that URL. That means, we would like to check that any navigation is permitted. This is how we can accomplish this by using
canActivateChild
:
{ path: '', canActivateChild: [AllowUrl], children: [ { path: ':folder', children: [ { path: '', component: ConversationsCmp }, { path: ':id', component: ConversationCmp, children: [...]} ] }, { path: 'contacts', children: [ { path: '', component: ContactsCmp }, { path: ':id', component: ContactCmp } ] } ] }
Where
AllowUrl
is defined like this:
@Injectable() class AllowUrl implements CanActivateChild...