From 8cbbcf4074917b858733029d601dc3c0be482c74 Mon Sep 17 00:00:00 2001 From: gentunian Date: Sat, 28 Jun 2025 21:54:30 -0300 Subject: [PATCH] fix(core): Make flattenRoutePath return a valid module flattenRoutePath method was returning an object instead of a module when path property was an empty string closes #15332 --- .../router/utils/flatten-route-paths.util.ts | 2 +- .../test/router/utils/flat-routes.spec.ts | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/core/router/utils/flatten-route-paths.util.ts b/packages/core/router/utils/flatten-route-paths.util.ts index fe0cff258a3..473e19b8192 100644 --- a/packages/core/router/utils/flatten-route-paths.util.ts +++ b/packages/core/router/utils/flatten-route-paths.util.ts @@ -14,7 +14,7 @@ export function flattenRoutePaths(routes: Routes) { if (item.children) { const childrenRef = item.children as Routes; childrenRef.forEach(child => { - if (!isString(child) && child.path) { + if (!isString(child) && isString(child.path)) { child.path = normalizePath( normalizePath(item.path) + normalizePath(child.path), ); diff --git a/packages/core/test/router/utils/flat-routes.spec.ts b/packages/core/test/router/utils/flat-routes.spec.ts index fa0f13904f8..8900afe541e 100644 --- a/packages/core/test/router/utils/flat-routes.spec.ts +++ b/packages/core/test/router/utils/flat-routes.spec.ts @@ -17,6 +17,12 @@ describe('flattenRoutePaths', () => { @Module({}) class ChildModule4 {} @Module({}) + class ChildModule5 {} + @Module({}) + class ChildModule6 {} + @Module({}) + class ChildParentPathModule {} + @Module({}) class ParentChildModule {} @Module({}) class ChildChildModule2 {} @@ -70,6 +76,25 @@ describe('flattenRoutePaths', () => { ChildModule4, ], }, + { + path: 'child3', + children: [ + { + path: '', + module: ChildModule5, + children: [{ path: 'child', module: ChildParentPathModule }], + }, + ], + }, + { + path: 'child4', + children: [ + { + path: '/', + module: ChildModule6, + }, + ], + }, ], }, { path: '/v1', children: [AuthModule, CatsModule, DogsModule] }, @@ -91,6 +116,9 @@ describe('flattenRoutePaths', () => { }, { path: '/parent/child2', module: ChildModule4 }, { path: '/parent/child2/child', module: ChildModule3 }, + { path: '/parent/child3', module: ChildModule5 }, + { path: '/parent/child3/child', module: ChildParentPathModule }, + { path: '/parent/child4', module: ChildModule6 }, { path: '/v1', module: AuthModule }, { path: '/v1', module: CatsModule }, { path: '/v1', module: DogsModule },