From fbf3627f8a182b48bdacd6ca601d2c9411cf3fda Mon Sep 17 00:00:00 2001 From: Masahiko Sakakibara Date: Tue, 27 Aug 2019 01:28:45 +0900 Subject: [PATCH] feat(router): change to dynamic import (#176) --- schematics/page/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/schematics/page/index.ts b/schematics/page/index.ts index 6382fc4..9bd0d83 100644 --- a/schematics/page/index.ts +++ b/schematics/page/index.ts @@ -89,8 +89,8 @@ function addRouteToNgModule(options: PageOptions): Rule { const relativePath = buildRelativePath(module, pagePath); const routePath = strings.dasherize(options.routePath ? options.routePath : options.name); - const routeLoadChildren = `${relativePath}#${strings.classify(options.name)}PageModule`; - const changes = addRouteToRoutesArray(source, module, routePath, routeLoadChildren); + const ngModuleName = `${strings.classify(options.name)}PageModule`; + const changes = addRouteToRoutesArray(source, module, routePath, relativePath, ngModuleName); const recorder = host.beginUpdate(module); for (const change of changes) { @@ -105,7 +105,7 @@ function addRouteToNgModule(options: PageOptions): Rule { }; } -function addRouteToRoutesArray(source: ts.SourceFile, ngModulePath: string, routePath: string, routeLoadChildren: string): Change[] { +function addRouteToRoutesArray(source: ts.SourceFile, ngModulePath: string, routePath: string, routeLoadChildren: string, ngModuleName: string): Change[] { const keywords = findNodes(source, ts.SyntaxKind.VariableStatement); for (const keyword of keywords) { @@ -129,7 +129,7 @@ function addRouteToRoutesArray(source: ts.SourceFile, ngModulePath: string, rout changes.push(new InsertChange(ngModulePath, lastRouteNode.getEnd(), ',')); } - changes.push(new InsertChange(ngModulePath, lastRouteNode.getEnd() + 1, ` { path: '${routePath}', loadChildren: '${routeLoadChildren}' }${trailingCommaFound ? ',' : ''}\n`)); + changes.push(new InsertChange(ngModulePath, lastRouteNode.getEnd() + 1, ` {\n path: '${routePath}',\n loadChildren: () => import('${routeLoadChildren}').then( m => m.${ngModuleName})\n }${trailingCommaFound ? ',' : ''}\n`)); return changes; }