1

I have question about the lazy loading. Using Augury to detect my router tree structure.

enter image description here

app-routing.module.ts

const routes: Routes = [
  {
    path: '',
    children: [
      {
       path: 'reservation',
          loadChildren: () => import('./modules/reservations/reservations.module').then(mod => mod.ReservationsModule)
      },
      {
        path: 'add',
        loadChildren: () => import('./modules/add-autopoint/add-autopoint.module').then(mod => mod.AddAutopointModule)
      },
      {
        path: 'availability',
        loadChildren: () => import('./modules/availability/availability.module').then(mod => mod.AvailabilityModule)
      },
      {
        path: 'archive',
        loadChildren: () => import('./modules/archive/archive.module').then(mod => mod.ArchiveModule)
      },
      { path: '**', redirectTo: '/reservation', pathMatch: 'full' },
    ]
  }
];

Example module routing

reservation-routing.module.ts

const routes: Routes = [
  { path: '', component: ReservationComponent },
  { path: 'summary/:id', component: SummaryComponent, resolve: { summary: AtplSummaryResolver, notes: AtplNotesResolver } }
];

app.module.ts

@NgModule({
  declarations: [
    AppComponent,
    FilterPipe,
    LoaderComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    ReactiveFormsModule,
    SharedModule,
    NgxMatSelectSearchModule,
    FlexLayoutModule,
    AddAutopointModule,
    ArchiveModule,
    ReservationsModule,
    AvailabilityModule,
    Ng2LoadingSpinnerModule.forRoot({}),
    NavigationModule
  ],
  providers: [
    CommonService,
    AlertService,
    ListService,
    LoaderService,
    MenuService
  ],
  bootstrap: [AppComponent]
})

Is it normal to load these components at first or I'm doing something wrong ?

2 Answers 2

2

common services, components, pipes ..., used only in lazy-loaded modules, should be grouped in Shared Module, and this module is imported only in these lazy-loaded modules. other components, services and other things needed in the whole app (like authorization services or directives, layout components or services...) put it in a Core module imported in the App module. The Core module (and other modules imported in the App module) should be as lightweight as possible.

Sign up to request clarification or add additional context in comments.

Comments

1

After I remove these modules :

AddAutopointModule,

ArchiveModule,

ReservationsModule,

AvailabilityModule

from my app.module.ts i fixed my problem with the lazy loading

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.