角度2:NavigationCancel-导航ID 2不等于当前导航ID 3 [英] Angular 2: NavigationCancel - Navigation ID 2 is not equal to the current navigation id 3

查看:202
本文介绍了角度2:NavigationCancel-导航ID 2不等于当前导航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.

看Angular 2路由器源,当id !== this.navigationId(

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.

似乎可以在现有路由之间进行重定向,但不能在这些旧的哈希标记URL和现有路由之间进行重定向.路由器中是否必须同时存在这两个路由?

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.

推荐答案

我收到此错误是因为我连续连续两次调用router.navigate,(1附加queryParams,1附加片段),所以不得不重构我的只需调用一次导航的代码.

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.

这篇关于角度2:NavigationCancel-导航ID 2不等于当前导航ID 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆