Skip to content

Activation guard of child component affects creation/rendering of the parent component #18975

Closed as not planned

Description

@andrui

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

  1. added this to the Backlog milestone on Jan 23, 2018
  2. modified the milestones: Backlog, needsTriage on Feb 26, 2018
  3. atscott commented on May 29, 2020

    @atscott
    Contributor

    Hi @andrui, what would you expect the URL to be when you navigate directly to /comp_a/comp_b/comp_c when the guard for child comp_c returns false? Should it be /comp_a/comp_b or 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.

  4. andrui commented on May 30, 2020

    @andrui
    Author

    @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.

  5. modified the milestones: Backlog, needsTriage on Jul 10, 2020
  6. modified the milestones: needsTriage, Backlog on Jul 21, 2020
  7. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    and removed on Oct 1, 2020
  8. atscott commented on Jun 27, 2022

    @atscott
    Contributor

    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.

  9. modified the milestones: Backlog, Fixit H1'2022 on Jun 27, 2022
  10. angular-automatic-lock-bot commented on Jul 28, 2022

    @angular-automatic-lock-bot

    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.

  11. locked and limited conversation to collaborators on Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions