Description
🐞 bug report
Affected Package
@angular/router
Description
The state passed to router.navigate is lost when doing multiple navigations.
🔬 Minimal Reproduction
https://stackblitz.com/edit/angular-nrjzxe
Pressing 'FOO' will call router.navigate with state { foo: true }.
If you press it once, you will see in the console that the resolver can see this state (via getCurrentNavigation).
If you press it multiple times quickly (the resolver takes two seconds), all but the last navigation are canceled and during the navigations past the initial one, the resolver can no longer see this state.
I would expect to always be able to access the state from the resolver.
🌍 Your Environment
Angular version 7.2.5
EDIT: Some more info:
Looks like currentNavigation is set to null here:
angular/packages/router/src/router.ts
Line 721 in fd5cd10
It is then null here, contradicting the '!' non-null assertion operator:
angular/packages/router/src/router.ts
Line 506 in fd5cd10
Thus you are left with a currentNavigation only containing finalUrl.
Activity
pcurrivan commentedon Mar 30, 2019
Moving the setting of currentNavigation:
angular/packages/router/src/router.ts
Line 457 in fd5cd10
angular/packages/router/src/router.ts
Line 474 in fd5cd10
jasonaden commentedon Apr 1, 2019
Thanks for the detailed analysis! It appears this does fix the problem. I created a PR to get this addressed.
fix(router): adjust setting navigationTransition when a new navigatio…
fix(router): adjust setting navigationTransition when a new navigatio…
fix(router): adjust setting navigationTransition when a new navigatio…
angular-automatic-lock-bot commentedon Sep 14, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.