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

查看:26
本文介绍了Angular 2: NavigationCancel - Navigation ID 2 不等于当前导航 id 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将旧 URL(电子邮件模板中的链接)从以前的站点重定向到另一条路径,如下所示:

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:

导航 ID 2 不等于当前导航 ID 3.

查看 Angular 2 路由器源码,当 id !== this.navigationId (https://github.com/angular/angular/blob/master/modules/@angular/router/src/router.ts#L652).我找不到关于 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?

非常感谢您的帮助.

推荐答案

我收到这个错误,因为我快速连续两次调用 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.

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

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