What all could be the reasons for a NavigationCancel event to get triggered?
NavigationCancel
will be triggered when you are trying to naviggate to a route and navigated route children can not be loaded (CanLoad guard) or route itself cannot be activated (CanActivate guard)
you may use {enableTracing : true}
while configuring RouterModule
to see all events, and analyze further.
Hope this helps!!
This is late, but i hope it might help someone else, as I had struggled with this also.
So, another reason this could be happening is that the navigation event is triggered twice.
This happened to me by mistake, because i had a component with a routerLink
directive that had an input binding with the same name:
my-component Class:
@Input() routerLink: string[];
my-component Template:
...
<a [routerLink]="routerLink">
...
The parent component template was like this :
...
<my-component
[routerLink]="somePath"
...
>
Which was actually creating another routerLink
directive binding.
As a result the navigation event was firing twice, almost simultaneously, which produced the NavigationCancel
event.