-
Notifications
You must be signed in to change notification settings - Fork 26.2k
The state passed to router.navigate is lost when doing multiple navigations #29389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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
|
…n cancels an existing one Prior to this change, if a navigation was ongoing and a new one came in, the router could get into a state where `router.currentNavigation` was `null` even though a navigation was executing. This change moves where we set the `currentNavigation` value so it's inside a `switchMap`. This solves the problem because the `finally` on the `switchMap` had been setting `currentNavigation` to `null` but the new `currentNavigation` value would have already been set. Essentially this was a timing problem and is resolved with this change. Fixes angular#29389 angular#29590
Thanks for the detailed analysis! It appears this does fix the problem. I created a PR to get this addressed. |
…n cancels an existing one Prior to this change, if a navigation was ongoing and a new one came in, the router could get into a state where `router.currentNavigation` was `null` even though a navigation was executing. This change moves where we set the `currentNavigation` value so it's inside a `switchMap`. This solves the problem because the `finally` on the `switchMap` had been setting `currentNavigation` to `null` but the new `currentNavigation` value would have already been set. Essentially this was a timing problem and is resolved with this change. Fixes angular#29389 angular#29590
…n cancels an existing one (#29636) Prior to this change, if a navigation was ongoing and a new one came in, the router could get into a state where `router.currentNavigation` was `null` even though a navigation was executing. This change moves where we set the `currentNavigation` value so it's inside a `switchMap`. This solves the problem because the `finally` on the `switchMap` had been setting `currentNavigation` to `null` but the new `currentNavigation` value would have already been set. Essentially this was a timing problem and is resolved with this change. Fixes #29389 #29590 PR Close #29636
…n cancels an existing one (angular#29636) Prior to this change, if a navigation was ongoing and a new one came in, the router could get into a state where `router.currentNavigation` was `null` even though a navigation was executing. This change moves where we set the `currentNavigation` value so it's inside a `switchMap`. This solves the problem because the `finally` on the `switchMap` had been setting `currentNavigation` to `null` but the new `currentNavigation` value would have already been set. Essentially this was a timing problem and is resolved with this change. Fixes angular#29389 angular#29590 PR Close angular#29636
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 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.
The text was updated successfully, but these errors were encountered: