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 Guards inconsistency

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/router

Description

CanActivate, CanActivateChild and CanDeactivate wait for the first value emitted from the returned observable, while CanLoad waits for the observable to complete.

I find inconsistent how router guards behave, as it was stated in #25262.

It was stated that this behavior is documented, but it’s not. The documentation says that

The Router guards require an observable to complete

, but it’s not true. CanActivate and other guards don’t require it.

Even if it was well documented, I think this behavior should be standardized. What do you think? 😃

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-canload-test

🌍 Your Environment

Angular Version:




Angular CLI: 7.1.1
Node: 8.11.1
OS: darwin x64
Angular: 7.1.1
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, http, language-service, material, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.1
@angular-devkit/build-angular     0.11.1
@angular-devkit/build-optimizer   0.11.1
@angular-devkit/build-webpack     0.11.1
@angular-devkit/core              7.1.1
@angular-devkit/schematics        7.1.1
@angular/pwa                      0.11.1
@ngtools/webpack                  7.1.1
@schematics/angular               7.1.1
@schematics/update                0.11.1
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
benleshcommented, Dec 13, 2018

It looks like we need to look at changing this feature in the long-term, but in the short term we should update the docs to be more accurate.

1reaction
atscottcommented, May 24, 2021

Closing as obsolete. Updating the above example shows that the guards do not need to complete and that they all work the same. https://github.com/angular/angular/blob/cb48bde35d24f78f93e38fe487a0c42fee234ce6/packages/router/src/operators/check_guards.ts#L124

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Spanning Tree PVID- and Type-Inconsistencies
Loop inconsistency—This is detected by the Loop Guard feature. For more information, refer to Spanning-Tree Protocol Enhancements using Loop ...
Read more >
Angular router activates wrong route guard - Stack Overflow
Navigating directly to a route like /activate , for example, causes a discrepancy between router state and angular router state, ...
Read more >
canLoad guard does not subscribe to Observable<boolean>
The Router guards require an Observable to complete , meaning it has emitted ... So there is a real inconsistency about guards behavior...
Read more >
Configuring Root Guard & Loop Guard - mrn-cciew
If a loop guard enabled root or blocked port stop a receiving BPDUs from its designated port, it transitions to the loop-inconsistent blocking ......
Read more >
BPDU Protection for Spanning-Tree Protocols | Junos OS
MX Series routers, ACX Series routers, and EX Series switches support ... the interface transitioned to a BPDU inconsistent state, shutting down the ......
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