Skip to content

Repeated navigation attempts not possible when canDeactivate guard turns down initial navigation and urlUpdateStrategy set to "eager" #28561

Closed

Description

@larrifax

🐞 bug report

Affected Package

The issue is caused by package @angular/router

Is this a regression?

Yes, the previous version in which this bug was not present was: 7.2.0

Description

NB! I'm running with the Router's urlUpdateStrategy set to "eager".

I have a modal outlet, in which the routes have a canDeactivate guard preventing the user from closing the modal when there is pending changes. Until version 7.2.1, the user would be able to attempt to close the modal as many times as they wanted, triggering the guard every time. In version 7.2.1 and onwards, the guard is triggered the first time, but not on subsequent navigation attempts.

As far as I can see, this unexpected behavior is due to 6ae7aee. It seems like the following change is a bit aggressive:

this.browserUrlTree = t.urlAfterRedirects;

If you debug the above mentioned code in the reproduction, you'll see that the browserUrlTree is updated before the guard runs, and the changes aren't being undone when the guard denies navigation. This behavior will cause subsequent attempts to close the modal to stop at the following check:

!this.navigated || t.extractedUrl.toString() !== this.browserUrlTree.toString();

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-issue-repro2-yq1jm2

🔥 Exception or Error

None

🌍 Your Environment

Angular Version:





Anything else relevant?
Only happens when the Router's urlUpdateStrategy is set to "eager".

Activity

  1. added this to the needsTriage milestone on Feb 6, 2019
  2. jasonaden commented on May 14, 2019

    @jasonaden
    Contributor

    This should be fixed with a PR landing shortly: #30344

    Please let me know if this fixes it, and close this issue if so.

  3. larrifax commented on Jun 5, 2019

    @larrifax
    Author

    @jasonaden The bug is still present in 8.1.0-beta.0, which seems to be the first release in which #30344 is included.

    I've updated the repro to 8.1.0-beta.0 (https://stackblitz.com/edit/angular-issue-repro2-yq1jm2).

  4. FDIM commented on Oct 25, 2019

    @FDIM
    Contributor

    I've just bumped into this issue - Looks like it is still present in 8.2.9 and based on changelog probably in 8.2.12 as well

  5. modified the milestones: needsTriage, Backlog on Dec 3, 2019
  6. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    and removed on Oct 1, 2020
  7. atscott commented on Jan 13, 2021

    @atscott
    Contributor

    Additional reproduction due to dueling routerLink navigations: https://stackblitz.com/edit/angular-ivy-db9ngv?file=src%2Fapp%2Fapp-routing.module.ts (routerLink is applied to both the wrapper and the inner anchor, causing duplicate navigation attempts)

  8. atscott commented on Aug 10, 2021

    @atscott
    Contributor

    This is happening because the Router fails to reset the browserUrlTree when a navigation is rejected. This is resolved in the (currently private option) canceledNavigationResolution: 'computed'.

    Demo: https://stackblitz.com/edit/angular-issue-repro2-qzg9nn?file=src%2Fapp%2Fapp.component.ts

  9. atscott commented on Sep 8, 2021

    @atscott
    Contributor

    Closing as resolved by canceledNavigationResolution: 'computed' which will be available in v13

  10. angular-automatic-lock-bot commented on Oct 9, 2021

    @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.

  11. locked and limited conversation to collaborators on Oct 9, 2021
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

      Development

      No branches or pull requests

      Issue actions