Skip to content

Commit

Permalink
Retrieve lazy loaded child routes when getting modal routes in modal …
Browse files Browse the repository at this point in the history
…navigation service
  • Loading branch information
Fuzzy3 committed Feb 18, 2025
1 parent 13ac3c6 commit 62ec904
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 1 addition & 3 deletions apps/cookbook/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { HomeComponent } from './home/home.component';
import { IntroComponent } from './intro/intro.component';
import { ExtensionsLandingPageComponent } from './extensions/extensions-landing-page.component';
import { LocalizationComponent } from './localization/localization.component';
import { ExamplesRoutingModule } from './examples/examples-routing.module';

export const routes: Routes = [
{
Expand Down Expand Up @@ -70,7 +69,6 @@ export const routes: Routes = [
},
{
path: 'examples',
loadChildren: () =>
import('./examples/examples-routing.module').then((m) => m.ExamplesRoutingModule),
loadChildren: () => import('./examples/examples.routes').then((m) => m.EXAMPLE_ROUTES),
},
];
21 changes: 21 additions & 0 deletions libs/designsystem/modal/src/modal-navigation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class ModalNavigationService {
moduleRootRoutePath?: string
): Promise<string[]> {
const flattenedRoutes: Routes = [].concat(...routeConfig);
await this.addLazyLoadedChildRoutes(flattenedRoutes);

let modalRoutes: string[] = [];
const moduleRootPaths = await this.getModuleRootPath(flattenedRoutes, moduleRootRoutePath);
if (moduleRootPaths) {
Expand All @@ -45,6 +47,25 @@ export class ModalNavigationService {
return modalRoutes;
}

private async addLazyLoadedChildRoutes(flattenedRoutes: Routes) {
for (const route of flattenedRoutes) {
const lazyLoadedRoutes = await this.getLazyLoadedChildRoutes(route);
if (lazyLoadedRoutes.length) {
flattenedRoutes.push(...lazyLoadedRoutes);
}
}
}

private async getLazyLoadedChildRoutes(route: Route): Promise<Route[]> {
if (route?.loadChildren) {
const lazyLoadedChildren = await route.loadChildren();
if (Array.isArray(lazyLoadedChildren)) {
return lazyLoadedChildren;
}
}
return [];
}

private async getModuleRootPath(routes: Routes, moduleRootRoutePath?: string): Promise<string[]> {
if (moduleRootRoutePath) {
const trimmedPaths = moduleRootRoutePath
Expand Down

0 comments on commit 62ec904

Please sign in to comment.