Using loadChildren and loadComponent for lazy loading together in AppRoutingModule

Discussão em 'Angular' iniciado por builderfan, Dezembro 16, 2024.

  1. builderfan

    builderfan Guest

    I am using Angular 18 with modules as well as standalone components.

    In my AppRoutingModule I want to lazy load my standalone components as well as my modules with with loadComponent() and loadChildren(). But if I navigate to a lazy component route /lazyComponent and then refresh the page, after the page refreshes, the component is not loaded. I use bootstrapModule() in main.ts.

    Is it even possible or do i have to transform my modules to standalone components, too and then using bootstrapApplication()?

    My code in AppRoutingModule looks like:

    {
    path: 'orders',
    loadComponent: () => import('./orders/orders.component').then(m => m.OrdersComponent)
    },
    {
    path: 'addresses',
    loadChildren: () => import('./addresses/addresses.module').then(m => m.AddressesModule)
    },


    Also if I use

    { path: 'lazyComponent', component: LazyComponent },

    without lazy loading, refreshing the page doe not load the component.

    main.ts:

    platformBrowserDynamic().bootstrapModule(AppModule)
    .catch(err => console.error(err));

    Continue reading...

Compartilhe esta Página