Hi I think a better way is to preload you modules on background here an example :
Create a selective strategy :
import { Injectable } from '@angular/core';
import { PreloadingStrategy, Route } from '@angular/router';
import { loadavg } from 'os';
import { Observable, of } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class SelectiveStrategyService implements PreloadingStrategy {
constructor() {}
preload(route: Route, load: () => Observable<any>): Observable<any> {
if (route.data && route.data['preload']) {
return load();
}
return of(null);
}
}
Then load only the needed module :
import { NgModule } from '@angular/core';
import {
Routes,
RouterModule,
PreloadAllModules,
PreloadingStrategy,
} from '@angular/router';
import { SelectiveStrategyService } from './selective-strategy.service';
const routes: Routes = [
{
path: 'administration',
loadChildren: () =>
import('./administration/shell/shell.module').then((m) => m.ShellModule),
// pass preload to true on the needed module
data: { preload: true },
},
{
path: 'clients',
loadChildren: () =>
import('./client/client.module').then((m) => m.ClientlModule),
},
{ path: '**', redirectTo: '/administration', pathMatch: 'full' },
];
@NgModule({
imports: [
RouterModule.forRoot(routes, {
preloadingStrategy: SelectiveStrategyService,
}),
],
exports: [RouterModule],
})
export class AppRoutingModule {}