Visitar URL original
feat(router): Add canDeactivateChild guard by aahmedayed · Pull Request #44129 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20220123182837/https://github.com/angular/angular/pull/44129
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): Add canDeactivateChild guard #44129

Closed

Conversation

@aahmedayed
Copy link
Contributor

@aahmedayed aahmedayed commented Nov 10, 2021

Add canDeactivateChild to determine if the current user is allowed to deactivate a child of the root.

resolves #11836

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Nov 10, 2021
@pullapprove pullapprove bot requested a review from atscott Nov 10, 2021
@aahmedayed aahmedayed force-pushed the add-canDeactivateChild-guard branch 2 times, most recently from 8ca974d to 95d178e Nov 10, 2021
this PR is to add `canDeactivateChild` to determine if the current user is allowed to deactivate a child of the root.

resolves angular#11836
@aahmedayed aahmedayed force-pushed the add-canDeactivateChild-guard branch from 95d178e to 50e8a52 Nov 10, 2021
@atscott
Copy link
Contributor

@atscott atscott commented Nov 11, 2021

Hi @aahmedayed, I appreciate you giving this a shot though I have a lot of concerns with the approach here.

  1. Mutating the TreeNode through nodeChildrenAsMap in this way is highly dependent on the traversal outside the function. That is, for it to work, it depends highly on how other code calls it. This is a pretty fragile approach and I've had my own difficulty updating other Router code because of similar decisions (specifically _urlSegmentGroup and _lastPathIndex which tightly couples the applyRedirects with recognize and createUrlTree in a way that would otherwise not be necessary).
  2. There aren't enough tests. Tests don't cover cases where canDeactivateChild returns true, nor is there any coverage for the interaction with runGuardsAndResolvers in the route config
  3. Each child config appears to inherit the canDeactivateChild from its ancestors. This seems like it would mean if there's a canDeactivateChild at level 1 in the tree and we're deactivating several children, that guard will execute many times rather than just the one time that should be necessary.
  4. The change is missing sufficient documentation. This should also be added to the aio/content/guide/router.md as well as having a section in router-tutorial-toh.md

I'm going to close this given the number scope of the concerns. Feel free to open a new PR if you have addressed these and want another review.

@atscott atscott closed this Nov 11, 2021
@aahmedayed
Copy link
Contributor Author

@aahmedayed aahmedayed commented Nov 11, 2021

Hi @atscott, Thank you for those explanations. I completely agree with you, i will try to get other solution for it this weekend.

@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Dec 12, 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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants