@@ -89,8 +89,8 @@ function addRouteToNgModule(options: PageOptions): Rule {
8989 const relativePath = buildRelativePath ( module , pagePath ) ;
9090
9191 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 ) ;
9494 const recorder = host . beginUpdate ( module ) ;
9595
9696 for ( const change of changes ) {
@@ -105,7 +105,7 @@ function addRouteToNgModule(options: PageOptions): Rule {
105105 } ;
106106}
107107
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 [ ] {
109109 const keywords = findNodes ( source , ts . SyntaxKind . VariableStatement ) ;
110110
111111 for ( const keyword of keywords ) {
@@ -129,7 +129,7 @@ function addRouteToRoutesArray(source: ts.SourceFile, ngModulePath: string, rout
129129 changes . push ( new InsertChange ( ngModulePath , lastRouteNode . getEnd ( ) , ',' ) ) ;
130130 }
131131
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` ) ) ;
133133
134134 return changes ;
135135 }
0 commit comments