Skip to content

Breaking undocumented change from Angular 13 to 14 in custom PreloadingStrategy. "preload"-method is called despite a set canLoad-guard. #47003

Closed

Description

@5te1n

Which @angular/* package(s) are the source of the bug?

core, router

Is this a regression?

Yes

Description

In Angular 13.3.10 the "preload"-Method in a custom PreloadingStrategy is not called for routes with a set canLoad-guard.
https://stackblitz.com/edit/angular-ivy-wf131m?file=src/app/app-routing.module.ts
This is also mentioned in the documentation: https://angular.io/guide/router-tutorial-toh#canload-blocks-preload

In Angular 14.0.0 this behaviour changed. The "preload"-method is called despite a set canLoad-guard. This change was not mentioned in the changelog and is the opposite of what is written in the documentation. Is this an intended change?
https://stackblitz.com/edit/angular-ivy-nabdle?file=src/app/app-routing.module.ts

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-ivy-nabdle?file=src/app/app-routing.module.ts

Please provide the exception or error you saw

The "preload"-method is called despite a set canLoad-guard in angular 14.

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

No response

Activity

  1. added this to the needsTriage milestone on Aug 1, 2022
  2. atscott commented on Aug 1, 2022

    @atscott
    Contributor

    Version 14 introduced the loadComponent for routes, which is not blocked by canLoad guards. This is why the preload method is still called. That said, the loadChildren is not called if there is a canLoad guard so I would not consider this a breaking change.

    The documentation could use an update and I will also adjust the code to not call the preload method in cases where there is a canLoad and no loadComponent. In this scenario, there is no need to call the preload method since nothing will be done with the result.

  3. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    on Aug 1, 2022
  4. modified the milestones: needsTriage, Backlog on Aug 1, 2022
  5. added a commit that references this issue on Aug 1, 2022
    ea03bd3
  6. 5te1n commented on Aug 2, 2022

    @5te1n
    Author

    @atscott Thank you. That sounds like a good solution. In my case, I wanted to preload the modules only after the user logged in. So I removed the canLoad-guards after the login and called Router.preload() manually.

  7. added a commit that references this issue on Aug 2, 2022
    79825d3
  8. angular-automatic-lock-bot commented on Sep 2, 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.

  9. locked and limited conversation to collaborators on Sep 2, 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

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: router

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions