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

docs(router): Deprecate canLoad guards in favor of canMatch #48180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Nov 22, 2022

As mentioned in #46021, canMatch guards can replace canLoad. There are slight differences between the two but the purpose of preventing user access to feature modules is still achievable. There are several reasons keeping CanLoad around is detrimental to the API surface:

  • Lazy loading should not be an architectural feature of an application. It's an optimization you do for code size. That is, there should not be an architectural feature in the router to directly specifically control whether to lazy load something or not based on conditions such as authentication. This is a slightly nuanced difference between the proposed canMatch guard: this guard would control whether you can use the route at all and as a side-effect, whether we download the code. CanLoad only specified whether the code should be downloaded so canMatch is more powerful and more appropriate.

  • The naming of CanLoad will be potentially misunderstood for the loadComponent feature. Because it applies to loadChildren, it feels reasonable to think that it will also apply to loadComponent. This isn’t the case: since we don't need to load the component until right before activation, we defer the loading until all guards/resolvers have run.

  • Unnecessary API surface bloat where two features (CanMatch and CanLoad) do essentially the same thing. This affects code size for supporting two nearly identical features as well as the learning and teaching journey for them both.

As mentioned in angular#46021, `canMatch` guards can replace `canLoad`. There
are slight differences between the two but the purpose of preventing
user access to feature modules is still achievable. There are several
reasons keeping `CanLoad` around is detrimental to the API surface:

* Lazy loading should not be an architectural feature of an application. It's an
optimization you do for code size. That is, there should not be an architectural
feature in the router to directly specifically control whether to lazy load something or
not based on conditions such as authentication. This is a slightly nuanced
difference between the proposed `canMatch` guard: this guard would control whether
you can use the route at all and as a side-effect, whether we download the code.
`CanLoad` only specified whether the code should be downloaded so `canMatch` is
more powerful and more appropriate.

* The naming of `CanLoad` will be potentially misunderstood for the `loadComponent` feature.
Because it applies to `loadChildren`, it feels reasonable to think that it will
also apply to `loadComponent`. This isn’t the case: since we don't need
to load the component until right before activation, we defer the
loading until all guards/resolvers have run.

* Unnecessary API surface bloat where two features (CanMatch and CanLoad) do
essentially the same thing. This affects code size for supporting two
nearly identical features as well as the learning and teaching journey
for them both.

DEPRECATED: CanLoad guards in the Router are deprecated. Use CanMatch
instead.
@atscott atscott added the target: minor This PR is targeted for the next minor release label Nov 22, 2022
@angular-robot angular-robot bot added detected: deprecation PR contains a commit with a deprecation area: docs Related to the documentation labels Nov 22, 2022
@ngbot ngbot bot added this to the Backlog milestone Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs Related to the documentation detected: deprecation PR contains a commit with a deprecation target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant