Skip to content

Commit

Permalink
feat(core): allow using modules and nested route trees in parallel
Browse files Browse the repository at this point in the history
change type of RouteTree.children to accept both RouteTree and Type<any> in junction

fixes #12700
  • Loading branch information
Kai Böse committed Nov 8, 2023
1 parent 7359a35 commit e1b1af9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/core/router/interfaces/routes.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Type } from '@nestjs/common';
export interface RouteTree {
path: string;
module?: Type<any>;
children?: Routes | Type<any>[];
children?: (RouteTree | Type<any>)[];
}

export type Routes = RouteTree[];
2 changes: 1 addition & 1 deletion packages/core/router/router-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class RouterModule {
}

private deepCloneRoutes(
routes: Routes | Type<any>[],
routes: (RouteTree | Type<any>)[],
): Routes | Array<Type<any>> {
return routes.map((routeOrType: Type<any> | RouteTree) => {
if (typeof routeOrType === 'function') {
Expand Down
16 changes: 16 additions & 0 deletions packages/core/test/router/utils/flat-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('flattenRoutePaths', () => {
@Module({})
class ChildModule2 {}
@Module({})
class ChildModule3 {}
@Module({})
class ChildModule4 {}
@Module({})
class ParentChildModule {}
@Module({})
class ChildChildModule2 {}
Expand Down Expand Up @@ -56,6 +60,16 @@ describe('flattenRoutePaths', () => {
},
],
},
{
path: '/child2',
children: [
{
path: 'child',
ChildModule3,
},
ChildModule4,
],
},
],
},
{ path: '/v1', children: [AuthModule, CatsModule, DogsModule] },
Expand All @@ -75,6 +89,8 @@ describe('flattenRoutePaths', () => {
path: '/parent/child/parentchild/childchild/child2child',
module: ChildChildModule2,
},
{ path: '/parent/child2', module: ChildModule4 },
{ path: '/parent/child2/child', module: ChildModule3 },
{ path: '/v1', module: AuthModule },
{ path: '/v1', module: CatsModule },
{ path: '/v1', module: DogsModule },
Expand Down

0 comments on commit e1b1af9

Please sign in to comment.