Router doesnt update URL for known routeguarded routes with HashLocationStrategy
See original GitHub issue🐞 bug report
Affected Package
The issue is caused by package @angular/router@10.0.10 (may have been present previously)Is this a regression?
UnknownDescription
Issue is only present when using the HashLocationStrategy.
When accessing a route within the same lazy routing module which has a guard returning a URL tree within the same routing module, the route is updating however the URL is not.
For example visit: https://angular-routeguard-redirect.netlify.app/#/register
Manipulate the URL to be: https://angular-routeguard-redirect.netlify.app/#/register/two
The guard will return a URL Tree redirecting you to ['/','register']
The route at https://angular-routeguard-redirect.netlify.app/#/register will be rendered
The URL will still be https://angular-routeguard-redirect.netlify.app/#/register/two
Refreshing causes the redirect to occur.
Routes /register
, /register/two
, /register/three
are all part of the same routing module (https://github.com/geometricpanda/routeguard-redirect/blob/master/src/app/pages/register/register-routing.module.ts)
which is loaded here https://github.com/geometricpanda/routeguard-redirect/blob/master/src/app/app-routing.module.ts
🔬 Minimal Reproduction
https://github.com/geometricpanda/routeguard-redirect hosted at https://angular-routeguard-redirect.netlify.app/#/register
🔥 Exception or Error
None Reported
🌍 Your Environment
Angular Version:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.0.6
Node: 14.2.0
OS: darwin x64
Angular: 10.0.10
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.6
@angular-devkit/build-angular 0.1000.6
@angular-devkit/build-optimizer 0.1000.6
@angular-devkit/build-webpack 0.1000.6
@angular-devkit/core 10.0.6
@angular-devkit/schematics 10.0.6
@angular/cli 10.0.6
@ngtools/webpack 10.0.6
@schematics/angular 10.0.6
@schematics/update 0.1000.6
rxjs 6.5.5
typescript 3.9.7
webpack 4.43.0
Anything else relevant?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Ah, yea this is definitely a bug. The logic which handles the redirection from the returned
UrlTree
assumes that the browser address bar was not yet updated (which would be the case if navigation were instead triggered throughrouter.navigate
).The scheduled navigation from the redirect gets ignored because the router thinks that the
browserUrlTree
already matches the attempted navigation. This is only partially accurate – while the navigation shouldn’t occur (we’re already on the/register
page since we never really navigated to/register/two
), the browser url still needs to be synced with the internal state.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.