Skip to content

The state passed to router.navigate is lost when doing multiple navigations #29389

Closed
@pcurrivan

Description

@pcurrivan

🐞 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:

this.currentNavigation = null;

It is then null here, contradicting the '!' non-null assertion operator:

...this.currentNavigation !,

Thus you are left with a currentNavigation only containing finalUrl.

Activity

added this to the needsTriage milestone on Mar 19, 2019
pcurrivan

pcurrivan commented on Mar 30, 2019

@pcurrivan
Author

Moving the setting of currentNavigation:

this.currentNavigation = {
to inside the switchMap at 474:
switchMap(t => {
seems to fix it. Is it that simple?

jasonaden

jasonaden commented on Apr 1, 2019

@jasonaden
Contributor

Thanks for the detailed analysis! It appears this does fix the problem. I created a PR to get this addressed.

added a commit that references this issue on Apr 1, 2019
947e341
added a commit that references this issue on Apr 1, 2019
e884c0c
added a commit that references this issue on Apr 17, 2019
880a585
angular-automatic-lock-bot

angular-automatic-lock-bot commented on Sep 14, 2019

@angular-automatic-lock-bot

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.

locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @jasonaden@pkozlowski-opensource@pcurrivan

      Issue actions

        The state passed to router.navigate is lost when doing multiple navigations · Issue #29389 · angular/angular