Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

angular2 routing - Angular 2: NavigationCancel - Navigation ID 2 is not equal to the current navigation id 3

I'm trying to redirect old URLs (links in email templates) from a previous site to another route like this:

if (route.url.indexOf('/#/') !== -1) {
    this.router.navigate(['/my-route']);
}

However, the navigation gets cancelled with the following reason:

Navigation ID 2 is not equal to the current navigation id 3.

Looking at the Angular 2 router source, this happens in the runNavigate method when id !== this.navigationId (https://github.com/angular/angular/blob/master/modules/@angular/router/src/router.ts#L652). I can't find any information about the navigationId property, why this happens and how to solve it.

Redirects between routes that exist seem to work, but not between these old hashmark URLs and existing routes. Do both routes have to exist in the router to be able to redirect between them?

Help would be very appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I got this error because I was calling router.navigate twice in quick succession, (1 to append queryParams, 1 to append a fragment) so had to refactor my code to only call navigate once.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...