Skip to content

Commit e73a86c

Browse files
committed
fix(router): support destructured lazy imports
closes #1319
1 parent 05365f0 commit e73a86c

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/utils/router-parser.util.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ export class RouterParserUtil {
114114
// CodeGenerator: "loadChildren":()=>import("./path")."then"("m"=>"m"."Module")
115115
// Both → loadChildren:"./path#Module"
116116
cleaned = cleaned
117+
.replace(
118+
/"?loadChildren"?:\(\)=>import\(["'`]([^"'`]+)["'`]\)\."?then"?\(\(\{["']?(\w+)["']?\}\)=>["']?\2["']?\)/g,
119+
'loadChildren:"$1#$2"',
120+
)
121+
.replace(
122+
/"?loadComponent"?:\(\)=>import\(["'`]([^"'`]+)["'`]\)\."?then"?\(\(\{["']?(\w+)["']?\}\)=>["']?\2["']?\)/g,
123+
'loadComponent:"$1#$2"',
124+
)
117125
.replace(
118126
/"?loadChildren"?:\(\)=>import\(["'`]([^"'`]+)["'`]\)\."?then"?\(\(?["']?\w+["']?\)?"?=>(?:["']?\w+["']?\.)?"?(\w+)"?\)/g,
119127
'loadChildren:"$1#$2"',

‎test/src/utils/router-parser.util.spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ describe("Utils - RouterParserUtil", () => {
152152
expect(result).not.to.include("[Function]");
153153
});
154154

155+
it('should convert loadChildren syntax using destructured then parameter to "path#Module" string (issue #1319)', () => {
156+
const result = routerParser.cleanRawRoute(
157+
"[{path:'admin',loadChildren:()=>import('./admin/admin.module').then(({AdminModule})=>AdminModule)}]",
158+
);
159+
expect(result).to.include(
160+
'loadChildren:"./admin/admin.module#AdminModule"',
161+
);
162+
expect(result).not.to.include("[Function]");
163+
});
164+
155165
it('should convert loadComponent arrow syntax to "path#Component" string', () => {
156166
const result = routerParser.cleanRawRoute(
157167
"[{path:'profile',loadComponent:()=>import('./profile/profile.component').then(m=>m.ProfileComponent)}]",

0 commit comments

Comments
 (0)