MOBILE-4470 core: Disable routes preloading

main
Noel De Martin 2024-03-04 16:47:01 +01:00
parent 9fc9b166a9
commit f82b14d2fd
2 changed files with 3 additions and 42 deletions

View File

@ -14,7 +14,6 @@
import { InjectionToken, Injector, ModuleWithProviders, NgModule, Type } from '@angular/core';
import {
PreloadAllModules,
RouterModule,
Route,
Routes,
@ -224,7 +223,7 @@ export const APP_ROUTES = new InjectionToken('APP_ROUTES');
@NgModule({
imports: [
RouterModule.forRoot([], { preloadingStrategy: PreloadAllModules }),
RouterModule.forRoot([]),
],
providers: [
{ provide: ROUTES, multi: true, useFactory: buildAppRoutes, deps: [Injector] },

View File

@ -18,39 +18,6 @@ import { Route, Routes } from '@angular/router';
import { ModuleRoutesConfig, isEmptyRoute, resolveModuleRoutes } from '@/app/app-routing.module';
const MAIN_MENU_TAB_ROUTES = new InjectionToken('MAIN_MENU_TAB_ROUTES');
const modulesPaths: Record<string, Set<string>> = {};
/**
* Get the name of the module the injector belongs to.
*
* @param injector Injector.
* @returns Injector module name.
*/
function getInjectorModule(injector: Injector): string | null {
if (!('source' in injector) || typeof injector.source !== 'string') {
return null;
}
// Get module name from R3Injector source.
// See https://github.com/angular/angular/blob/16.2.0/packages/core/src/di/r3_injector.ts#L161C8
return injector.source;
}
/**
* Get module paths.
*
* @param injector Injector.
* @returns Module paths.
*/
function getModulePaths(injector: Injector): Set<string> | null {
const module = getInjectorModule(injector);
if (!module) {
return null;
}
return modulesPaths[module] ??= new Set();
}
/**
* Build module routes.
@ -61,23 +28,18 @@ function getModulePaths(injector: Injector): Set<string> | null {
*/
export function buildTabMainRoutes(injector: Injector, mainRoute: Route): Routes {
const path = mainRoute.path ?? '';
const modulePaths = getModulePaths(injector);
const isRootRoute = modulePaths && !modulePaths.has(path);
const routes = resolveModuleRoutes(injector, MAIN_MENU_TAB_ROUTES);
mainRoute.path = path;
modulePaths?.add(path);
if (isRootRoute && !('redirectTo' in mainRoute)) {
if (!('redirectTo' in mainRoute)) {
mainRoute.children = mainRoute.children || [];
mainRoute.children = mainRoute.children.concat(routes.children);
} else if (isEmptyRoute(mainRoute)) {
return [];
}
return isRootRoute
? [mainRoute, ...routes.siblings]
: [mainRoute];
return [mainRoute, ...routes.siblings];
}
@NgModule()