What could be the causes of the NavigationCancel event?

I have a subscription to router events in angular2 . When I console the event, I find the NavigationCancel event with reason: "" . Curious to know what could be the reason for the NavigationCancel to trigger. Not only with the base empty , but in general.

+6
source share
2 answers

NavigationCancel will fire when you try to switch to a route, and moved routes cannot be loaded by children (CanLoad guard) or the route itself cannot be activated (CanActivate guard)

you can use {enableTracing : true} when configuring the RouterModule to view all events and further analysis.

Hope this helps!

+6
source

It's already late, but I hope this can help someone else, as I also struggled with this.

So, another reason this can happen is because the navigation event is fired twice.

This happened to me by mistake, because I had a component with the 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 actually created another routerLink directive. As a result, the navigation event fired twice, almost simultaneously, which led to the NavigationCancel event.

0
source

Source: https://habr.com/ru/post/1268559/


All Articles