Skip to content

Preloading of nested lazy modules does not work #49558

Closed

Description

@Eugeno

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

router

Is this a regression?

No

Description

Preload only works for siblings, not children.
For example, there is a structure:

graph LR
pages --> b
pages --> c
b --> b-review
b --> b-detail
b-detail --> b-maintenance
b-detail --> b-additional
Loading

If you go to /pages/c you'll get only b preloaded. But you could have a link on /pages/c to pages/b/detail/1/maintenance. Therefore, I want to get b-index, b-detail-index, b-detail-component, and b-maintenance preloaded.

Stackblitz: https://stackblitz.com/edit/angular-uc5bt8

Please provide a link to a minimal reproduction of the bug

https://github.com/Eugeno/a-f

Please provide the exception or error you saw

No response

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

Angular CLI: 15.2.4
Node: 16.14.0
Package Manager: npm 8.3.0
OS: win32 x64

Angular: 15.2.3
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1502.4
@angular-devkit/build-angular   15.2.4
@angular-devkit/core            15.2.4
@angular-devkit/schematics      15.2.4
@angular/cli                    15.2.4
@schematics/angular             15.2.4
rxjs                            7.8.0
typescript                      4.9.5

Anything else?

No response

Activity

  1. Eugeno commented on Mar 23, 2023

    @Eugeno
    Author

    Here's a hacky solution for preloading nested lazy routes:

    const routes: Routes = [
      {
        path: '',
        component: PagesComponent,
        children: [
          /*...*/ // regular children
    
          // nested routes from another modules
          {
            path: 'fake',
            loadComponent: () => import('./+b/b-index/b-index.component').then((m) => m.BIndexComponent),
            canActivate: [permissionsGuard], // disallow
          },
        ],
      },
    ];

    Thanks to @stevermeister for this idea.

  2. added this to the needsTriage milestone on Mar 23, 2023
  3. added a commit that references this issue on Mar 23, 2023
    4898fd4
  4. atscott commented on Mar 23, 2023

    @atscott
    Contributor

    There are actually 2 issues here. On is a Router bug (which you can get around by changing children: [...] to loadChildren: () => [...] but the other in your example is that your preloading function is returning Observable<Observable<any>> because of the map returning an Observable.

    https://stackblitz.com/edit/angular-g7jdc3?file=src%2Fapp%2Fpages%2F%2Bb%2Fb-routing.module.ts

  5. Eugeno commented on Mar 24, 2023

    @Eugeno
    Author

    @atscott thanks you so much for your quick response and for proposing a working solution to the issue. Much appreciated!

  6. added a commit that references this issue on Mar 24, 2023
    978d37f
  7. angular-automatic-lock-bot commented on Apr 24, 2023

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

  8. locked and limited conversation to collaborators on Apr 24, 2023
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions