question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Re-navigating to a the same url during an active navigation causes cancellation without a new navigation starting

See original GitHub issue

🐞 bug report

Affected Package

@angular/router

Is this a regression?

No

Description

While the router is in the route activation phase if it receives another navigation request that results in the same url the active navigation will be canceled, but the new navigation won’t start. This only occurs when onSameUrlNavigation=false (the default). I would expect that a NavigationEnd event would be emitted for either the first or replacement navigation, but currently one is never emitted.

🔬 Minimal Reproduction

https://angular-fz4k5d.stackblitz.io Click the “Test” link to navigate to navigate to /test?query=someText

NavigationStart {id: 1, url: "/", navigationTrigger: "imperative", restoredState: null}
RoutesRecognized {id: 1, url: "/", urlAfterRedirects: "/404", state: RouterStateSnapshot}
GuardsCheckStart {id: 1, url: "/", urlAfterRedirects: "/404", state: RouterStateSnapshot}
ChildActivationStart {snapshot: ActivatedRouteSnapshot}
ActivationStart {snapshot: ActivatedRouteSnapshot}
GuardsCheckEnd {id: 1, url: "/", urlAfterRedirects: "/404", state: RouterStateSnapshot, shouldActivate: true}
ResolveStart {id: 1, url: "/", urlAfterRedirects: "/404", state: RouterStateSnapshot}
ResolveEnd {id: 1, url: "/", urlAfterRedirects: "/404", state: RouterStateSnapshot}
ActivationEnd {snapshot: ActivatedRouteSnapshot}
ChildActivationEnd {snapshot: ActivatedRouteSnapshot}
NavigationEnd {id: 1, url: "/", urlAfterRedirects: "/404"}
Scroll {routerEvent: NavigationEnd, position: null, anchor: null

### Click test link
NavigationStart {id: 2, url: "/test?query=someText", navigationTrigger: "imperative", restoredState: null}
RoutesRecognized {id: 2, url: "/test?query=someText", urlAfterRedirects: "/test?query=someText", state: RouterStateSnapshot}
GuardsCheckStart {id: 2, url: "/test?query=someText", urlAfterRedirects: "/test?query=someText", state: RouterStateSnapshot}
ChildActivationStart {snapshot: ActivatedRouteSnapshot}
ActivationStart {snapshot: ActivatedRouteSnapshot}
GuardsCheckEnd {id: 2, url: "/test?query=someText", urlAfterRedirects: "/test?query=someText", state: RouterStateSnapshot, shouldActivate: true}
ResolveStart {id: 2, url: "/test?query=someText", urlAfterRedirects: "/test?query=someText", state: RouterStateSnapshot}
ResolveEnd {id: 2, url: "/test?query=someText", urlAfterRedirects: "/test?query=someText", state: RouterStateSnapshot}

### navigate from component constructor loaded through route activation triggers previous navigation to cancel
### This navigation is also to /test?query=someText
NavigationCancel {id: 2, url: "/test?query=someText", reason: "Navigation ID 2 is not equal to the current navigation id 3"}

### I think these are left over from id=2
ActivationEnd {snapshot: ActivatedRouteSnapshot}
ChildActivationEnd {snapshot: ActivatedRouteSnapshot}

### No NavigationEnd event fires for navigating to /test?query=someText (for id=2 nor id=3)
### No Navigation events fire for id=3

🌍 Your Environment

Angular Version: 8.2.14

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
YogliBcommented, Dec 9, 2020

This is still happening on Angular@10, when re-navigation is triggered from inside of a Guard.

1reaction
zhengsansancommented, Apr 7, 2021

这个问题有解决方案吗? 原因分析: 经过跟踪代码,我发现是因为在组件ngOnDestroy的时候重复调用了一次路由跳转的方法,然而this.router.navigate每执行一次navigationId就会+1,这样就造成了navigationId不匹配,路由事件被取消; 解决办法: 删除组件中ngOnDestroy里重复调用navigate的方法,问题解决之。同理,其它类似的问题也因该是路由的重复调用引起的,建议大家仔细排查代码,删除重复的里有调用即可。

Read more comments on GitHub >

github_iconTop Results From Across the Web

Navigation is canceled when you browse to Web pages that ...
Describes a problem in which Internet Explorer may stop responding when you browse to Web pages that in different Internet Explorer security zones....
Read more >
Angular: Refetch data on same URL navigation - Medium
The first approach is to tell the Angular router to emit the route events on refresh and then handle them accordingly in our...
Read more >
Navigation Menu - Salesforce Help
The Navigation Menu component extends your site's navigation beyond navigational topics. Navigation menu items can include Salesforce objects, topics, pag.
Read more >
Connect to your world with Connected Navigation options ...
Connected Built-In Navigation: Navigation services require SYNC® 4 and FordPass Connect (optional on select vehicles), complimentary Connected Service and the ...
Read more >
Buttons - Lightning Design System
Use a link when you're navigating to another place, such as: a "view all" page, ... If pressing a Button results in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found