@@ -89,8 +89,8 @@ function addRouteToNgModule(options: PageOptions): Rule {
89
89
const relativePath = buildRelativePath ( module , pagePath ) ;
90
90
91
91
const routePath = strings . dasherize ( options . routePath ? options . routePath : options . name ) ;
92
- const routeLoadChildren = `${ relativePath } # ${ strings . classify ( options . name ) } PageModule` ;
93
- const changes = addRouteToRoutesArray ( source , module , routePath , routeLoadChildren ) ;
92
+ const ngModuleName = `${ strings . classify ( options . name ) } PageModule` ;
93
+ const changes = addRouteToRoutesArray ( source , module , routePath , relativePath , ngModuleName ) ;
94
94
const recorder = host . beginUpdate ( module ) ;
95
95
96
96
for ( const change of changes ) {
@@ -105,7 +105,7 @@ function addRouteToNgModule(options: PageOptions): Rule {
105
105
} ;
106
106
}
107
107
108
- function addRouteToRoutesArray ( source : ts . SourceFile , ngModulePath : string , routePath : string , routeLoadChildren : string ) : Change [ ] {
108
+ function addRouteToRoutesArray ( source : ts . SourceFile , ngModulePath : string , routePath : string , routeLoadChildren : string , ngModuleName : string ) : Change [ ] {
109
109
const keywords = findNodes ( source , ts . SyntaxKind . VariableStatement ) ;
110
110
111
111
for ( const keyword of keywords ) {
@@ -129,7 +129,7 @@ function addRouteToRoutesArray(source: ts.SourceFile, ngModulePath: string, rout
129
129
changes . push ( new InsertChange ( ngModulePath , lastRouteNode . getEnd ( ) , ',' ) ) ;
130
130
}
131
131
132
- changes . push ( new InsertChange ( ngModulePath , lastRouteNode . getEnd ( ) + 1 , ` { path: '${ routePath } ', loadChildren: '${ routeLoadChildren } ' }${ trailingCommaFound ? ',' : '' } \n` ) ) ;
132
+ changes . push ( new InsertChange ( ngModulePath , lastRouteNode . getEnd ( ) + 1 , ` {\n path: '${ routePath } ',\n loadChildren: () => import( '${ routeLoadChildren } ').then( m => m. ${ ngModuleName } )\n }${ trailingCommaFound ? ',' : '' } \n` ) ) ;
133
133
134
134
return changes ;
135
135
}
0 commit comments