From f82b14d2fd0c4a92a0073ccab5741bc1b058a9e3 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 4 Mar 2024 16:47:01 +0100 Subject: [PATCH] MOBILE-4470 core: Disable routes preloading --- src/app/app-routing.module.ts | 3 +- .../mainmenu/mainmenu-tab-routing.module.ts | 42 +------------------ 2 files changed, 3 insertions(+), 42 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index b75eaba23..9409e6768 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -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] }, diff --git a/src/core/features/mainmenu/mainmenu-tab-routing.module.ts b/src/core/features/mainmenu/mainmenu-tab-routing.module.ts index 952582c39..8ecc4d138 100644 --- a/src/core/features/mainmenu/mainmenu-tab-routing.module.ts +++ b/src/core/features/mainmenu/mainmenu-tab-routing.module.ts @@ -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> = {}; - -/** - * 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 | 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 | 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()