Repository navigation
Activation guard of child component affects creation/rendering of the parent component #18975
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Preconditions: there is a nested routing tree (like /comp_a/comp_b/comp_c) with activation guards for each component. Activation guards of all components return "true" after some async operation/timeout.
UseCase 1.1
open comp_a => waiting for CompA guard => render CompA
open comp_b => waiting for CompB guard => render CompB
open comp_c => waiting for CompC guard => render CompC
UseCase 1.2
open /comp_a/comp_b/comp_c => waiting for CompA guard => waiting for CompB guard => waiting for CompC guard => render CompA + render CompB + render CompC
Preconditions: there is a nested routing tree (like /comp_a/comp_b/comp_c) with activation guards for each component. Activation guards of all components except the last one return "true" after some async operation/timeout. Guard of the last component returns "false" after some async operation/timeout.
UseCase 2.1
open comp_a => waiting for CompA guard => render CompA
open comp_b => waiting for CompB guard => render CompB
open comp_c => waiting for CompC guard => don't render CompC
UseCase 2.2
open /comp_a/comp_b/comp_c => waiting for CompA guard => waiting for CompB guard => waiting for CompC guard => don't render components at all
Expected behavior
"UseCase 1.1" and "UseCase 2.1" are ok
For "UseCase 1.2" expected:
open /comp_a/comp_b/comp_c => waiting for CompA guard => render CompA => waiting for CompB guard => render CompB => waiting for CompC guard => render CompC
For "UseCase 2.2" expceted:
open /comp_a/comp_b/comp_c => waiting for CompA guard => render CompA => waiting for CompB guard => render CompB => waiting for CompC guard => don't render CompC
Minimal reproduction of the problem with instructions
https://plnkr.co/edit/xpkHSCSEzTK9yoAPJbvG?p=preview
STR:
- click "show components"
- there will be log where guards are resolved one-by-one
- all components are appeared only after all guards are resolved
The issue is related to the b9e32c8
I totally agree that child CanActivate guard should wait for parent to comple, but parent components creation/rendering should not be affected by by child CanActivate guard (activation of the parent route snapshout should not wait until all child CanActivate guards are resolved successfully)
Environment
Angular version: 4.3.3
Activity
atscott commentedon May 29, 2020
Hi @andrui, what would you expect the URL to be when you navigate directly to
/comp_a/comp_b/comp_cwhen the guard for childcomp_creturnsfalse? Should it be/comp_a/comp_bor remain/comp_a/comp_b/comp_c?I can see how it could be useful to fall back to the nearest activatable ancestor. I feels a bit like a useful feature request more than the current functionality being broken.
andrui commentedon May 30, 2020
@atscott It would be great to have configurable "route reject strategy". I mean that default strategy can be left as is in orderd to not break backward compatibility. Additional option(s) can be introduced e.g. to fall back to the nearest activatable ancestor.
atscott commentedon Jun 27, 2022
Closing as working as designed. A guard rejecting cancels the entire navigation. If you want to render part of the attempted navigation, the guard should redirect to the partial URL.
angular-automatic-lock-bot commentedon Jul 28, 2022
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.