question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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?

Unknown

Description

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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
atscottcommented, Sep 1, 2020

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 through router.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.

0reactions
angular-automatic-lock-bot[bot]commented, Oct 18, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2 Routing Does Not Work When Deployed to Http ...
This problem is solved by implementing HashLocationStrategy which adds # to all your routes. You achieve this by adding HashLocationStrategy ...
Read more >
Common Routing Tasks
This topic describes how to implement many of the common tasks associated with adding the Angular router to your application.
Read more >
Angular 2: Guarding routes
In this blog I'll show you how to guard routes in Angular 2 Router. Let's consider some scenarios that require a certain validation...
Read more >
Routing Strategies • Angular - codecraft.tv
The default client-side routing strategy used in Angular is the PathLocationStrategy. This changes the URL programmatically using the HTML5 History API in ...
Read more >
Chapter 3. Navigation with the Angular router
Not only do you want to be able to change the view inside the page, ... edh cwrn Angular er gxc rod HashLocationStrategy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found