Skip to content

fix(core): Make flattenRoutePath return a valid module #15333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/router/utils/flatten-route-paths.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down
28 changes: 28 additions & 0 deletions packages/core/test/router/utils/flat-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe('flattenRoutePaths', () => {
@Module({})
class ChildModule4 {}
@Module({})
class ChildModule5 {}
@Module({})
class ChildModule6 {}
@Module({})
class ChildParentPathModule {}
@Module({})
class ParentChildModule {}
@Module({})
class ChildChildModule2 {}
Expand Down Expand Up @@ -70,6 +76,25 @@ describe('flattenRoutePaths', () => {
ChildModule4,
],
},
{
path: 'child3',
children: [
{
path: '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also add the case where path: '/'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing. To better understand your suggestion, are you asking for the root parent of a route or for any child inside it?

Just in case, this PR only tries to fix the case where the path is an empty string the module property would be set to be the object being passed as a route configuration. That derives to the actual module not having the MODULE_PATH metadata set due to the fact that the metadata is set to a plain object instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root can be anything but the child will have the path: '/' just for completeness sake

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just added it. Let me know if that feels good to you. Thanks.

module: ChildModule5,
children: [{ path: 'child', module: ChildParentPathModule }],
},
],
},
{
path: 'child4',
children: [
{
path: '/',
module: ChildModule6,
},
],
},
],
},
{ path: '/v1', children: [AuthModule, CatsModule, DogsModule] },
Expand All @@ -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 },
Expand Down