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.

Navigating to lazy loaded module from route guard causes the URL path to briefly be blank

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/router

Is this a regression?

Not sure

Description

If you have a page that is protected by a route guard which triggers a redirect (thus cancelling the current navigation) to a page which is lazy-loaded, the URL will briefly read just the host name (/) while the module loads. (An example of this would be having a dashboard that’s protected by a user login guard that redirects to the login page (which in my case is lazy-loaded).)

This is further an issue because it changes the history so that if the user hits the back button, they will be taken to / rather than the page they originally tried to navigate to.

Also, if there is a network issue retrieving the module, the user will be abandoned on the home page. If they refresh to try to fix the issue, they will no longer be where they started.

🔬 Minimal Reproduction

angular-lazy-load-guard-test.zip

Navigate to /page1 and you should get redirected to /page2. However, notice that the URL briefly reads /. If this is not apparent, try adding network throttling (a Firefox feature) to slow down the retrieval of the lazy module.

I also have a second redirect that emulates the behavior of the guard in the Page1Component. If you disable the card, the page1 component will still redirect. However, note that the URL never reads blank at this point…it always shows something.

🔥 Exception or Error

N/A

🌍 Your Environment

Angular Version:


Angular CLI: 9.0.7
Node: 12.3.1
OS: linux x64

Angular: 9.0.7
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.7
@angular-devkit/build-angular     0.900.7
@angular-devkit/build-optimizer   0.900.7
@angular-devkit/build-webpack     0.900.7
@angular-devkit/core              9.0.7
@angular-devkit/schematics        9.0.7
@ngtools/webpack                  9.0.7
@schematics/angular               9.0.7
@schematics/update                0.900.7
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chris13524commented, Mar 24, 2020

If this is going to be closed, then the example in the documentation should also be updated: https://angular.io/guide/router#canactivate-requiring-authentication

0reactions
angular-automatic-lock-bot[bot]commented, Jun 14, 2020

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

Lazy loading of Module routing path issue - Stack Overflow
Here I have two routes one is default route that is blank and one is welcome screen in AppModule . It contains one...
Read more >
Router tutorial: tour of heroes - Angular
In this tutorial, you build upon a basic router configuration to explore features such as child routes, route parameters, lazy load NgModules, guard...
Read more >
Angular Lazy Load Routing with Route Guards Part-1 - YouTube
How to create an Angular Lazy Loading project with Route Guards ...
Read more >
Ionic Navigation and Angular Routing: The Ultimate Guide
Ionic 2 and 3 ditched URL based navigation in favor of a more app-like push/pop ... Lazy Loading Modules in Ionic with the...
Read more >
Lazy loading React components - LogRocket Blog
One way to split code is to use dynamic imports, which leverage the import() syntax. Calling import() to load a module relies on...
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