Skip to content

canceledNavigationResolution: computed + canDeactivate: false results unexpected behavior #50983

Closed

Description

@JounQin

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

Yes

Description

iShot_2023-07-10_15.51.35.mp4

When clicking back button in /edit page, the location is changed to /list unexpectedly.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-rxjjhw

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 16.1.3
Node: 18.16.0
Package Manager: yarn 1.22.19
OS: darwin arm64

Angular: 16.1.3
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1601.3
@angular-devkit/build-angular   16.1.3
@angular-devkit/core            16.1.3
@angular-devkit/schematics      16.1.3
@schematics/angular             16.1.3
ng-packagr                      16.1.0
rxjs                            7.8.1

Anything else?

No response

Activity

  1. garrettld commented on Jul 11, 2023

    @garrettld
    Contributor

    This appears to be happening when you use location.back() or the browser back button to go back to the first page you loaded.

    The browser page id isn't being set on the first navigation, and the logic that restores the URL on cancelled navigation with this configuration appears to depend upon it being set. If you navigate once to another page before following your reproduction steps, the 'back' works fine because you're no longer going back to the initial navigation.

    I was able to work around this by doing an extra navigation when the app loads by calling this.router.navigateByUrl(this.router.url) in your root component's constructor, as shown in this modified reproduction: https://stackblitz.com/edit/stackblitz-starters-kqrprm?file=src%2Fmain.ts%3AL27,src%2Flist%2Fcomponent.ts

  2. added this to the needsTriage milestone on Jul 13, 2023
  3. JounQin commented on Aug 16, 2023

    @JounQin
    ContributorAuthor

    Any luck to resolve this issue?

  4. added a commit that references this issue on Aug 21, 2023
    fbdc92e
  5. added a commit that references this issue on Aug 21, 2023
    b0396e7
  6. angular-automatic-lock-bot commented on Sep 21, 2023

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

  7. locked and limited conversation to collaborators on Sep 21, 2023
  8. added a commit that references this issue on Jan 23, 2024
    97bc268
  9. added a commit that references this issue on Jan 31, 2024
    96d94ad
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