Skip to content
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

HashLocationStrategy does not change hash when redirecting in canActivate Guard #37048

Closed
tmair-red opened this issue May 11, 2020 · 3 comments
Closed
Labels
area: router freq2: medium P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent router: LocationStrategy router: navigation pipe events/scheduleNavigation/transitions observable state: confirmed type: bug/fix
Milestone

Comments

@tmair-red
Copy link

🐞 bug report

Affected Package

The issue is caused by package @angular/router

Is this a regression?

No, at least I can confirm that this issue was also present in version 8 of Angular

Description

Please have a look at the reproduction example at Stackblitz. The issue can be reproduced as follows:

  1. Open the application
  2. Change the URL in the URL Bar to .../#/bar and hit Enter OR change the location by entering location.href = '#/bar in the console.
  3. The state of the application does not change (this is expected as we are on /start)
  4. The URL still displays .../#/bar even though we have been redirected to /start.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-bejfwf

🌍 Your Environment

Angular Version:




Angular CLI: 8.3.24
Node: 12.16.1
OS: darwin x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.803.24
@angular-devkit/build-angular      0.803.24
@angular-devkit/build-optimizer    0.803.24
@angular-devkit/build-webpack      0.803.24
@angular-devkit/core               7.3.9
@angular-devkit/schematics         8.3.24
@angular/cdk                       8.2.3
@angular/cli                       8.3.24
@angular/flex-layout               8.0.0-beta.27
@angular/material                  8.2.3
@angular/material-moment-adapter   8.2.3
@ngtools/webpack                   8.3.24
@schematics/angular                8.3.24
@schematics/update                 0.803.24
rxjs                               6.5.4
typescript                         3.5.3
webpack                            4.39.2

Anything else relevant?

I tried to find the issue within the router code and it seems that this.browserUrlTree still points to /start on this lines: https://github.com/angular/angular/blob/acf6075ca9aa92121bb0166b2b7560aeb2c167ff/packages/router/src/router.ts#L474..L475
Therefore the angular router detects that the state of the application does not need to change (which is correct) but we still would need to change the URL to the one we redirected to.

@jaydeep987
Copy link

any update on this?

@jelbourn jelbourn added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed severity3: broken labels Oct 1, 2020
martinsik added a commit to martinsik/angular that referenced this issue Jan 13, 2021
…lTree from guard

This situation can probably happen only when using
HashLocationStrategy and by manually changing hash that triggers route
guards that return a new UrlTree. Then hash in the browser might not
match the current route because navigation was canceled, while hash in
the URL remained set by the user.

Fixes angular#37048
martinsik added a commit to martinsik/angular that referenced this issue Jan 27, 2021
…rategy

This situation can probably happen only when using
HashLocationStrategy and by manually changing hash that triggers a route
guard that returns a new UrlTree. Then hash in the browser might not
match the current route because navigation was canceled, while hash in
the URL remained set by the user.

Related to angular#37048
atscott pushed a commit to martinsik/angular that referenced this issue Apr 14, 2021
This situation can probably happen only when using
`HashLocationStrategy` and by manually changing hash that triggers a route
guard that returns a new `UrlTree`. Then hash in the browser might not
match the current route because navigation was canceled, while hash in
the URL remained set by the user.

Related to angular#37048
atscott pushed a commit to martinsik/angular that referenced this issue Apr 14, 2021
This situation can probably happen only when using
`HashLocationStrategy` and by manually changing hash that triggers a route
guard that returns a new `UrlTree`. Then hash in the browser might not
match the current route because navigation was canceled, while hash in
the URL remained set by the user.

Related to angular#37048
zarend pushed a commit that referenced this issue Apr 15, 2021
…40409)

This situation can probably happen only when using
`HashLocationStrategy` and by manually changing hash that triggers a route
guard that returns a new `UrlTree`. Then hash in the browser might not
match the current route because navigation was canceled, while hash in
the URL remained set by the user.

Related to #37048

PR Close #40409
zarend pushed a commit that referenced this issue Apr 15, 2021
…40409)

This situation can probably happen only when using
`HashLocationStrategy` and by manually changing hash that triggers a route
guard that returns a new `UrlTree`. Then hash in the browser might not
match the current route because navigation was canceled, while hash in
the URL remained set by the user.

Related to #37048

PR Close #40409
zarend pushed a commit that referenced this issue Apr 15, 2021
…40409)

This situation can probably happen only when using
`HashLocationStrategy` and by manually changing hash that triggers a route
guard that returns a new `UrlTree`. Then hash in the browser might not
match the current route because navigation was canceled, while hash in
the URL remained set by the user.

Related to #37048

PR Close #40409
@atscott
Copy link
Contributor

atscott commented Sep 21, 2021

@atscott atscott closed this as completed Sep 21, 2021
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: router freq2: medium P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent router: LocationStrategy router: navigation pipe events/scheduleNavigation/transitions observable state: confirmed type: bug/fix
Projects
None yet
Development

No branches or pull requests

5 participants