Skip to content

Commit f324108

Browse files
committed
fix(routing): Angular Import does not support return type
fix #1097
1 parent bc56fea commit f324108

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/utils/router-parser.util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class RouterParserUtil {
2323
private cleanModulesTree;
2424
private modulesWithRoutes = [];
2525
private transformAngular8ImportSyntax =
26-
/(['"]loadChildren['"]:)\(\)=>"import\((\\'|'|")([^'"]+?)(\\'|'|")\)\.then\(\w+?=>\S+?\.([^)]+?)\)(\\'|'|")/g;
26+
/(['"]loadChildren['"]:)\(\)(:[^)]+?)?=>"import\((\\'|'|")([^'"]+?)(\\'|'|")\)\.then\(\(?\w+?\)?=>\S+?\.([^)]+?)\)(\\'|'|")/g;
2727

2828
private static instance: RouterParserUtil;
2929
private constructor() {}
@@ -63,14 +63,14 @@ export class RouterParserUtil {
6363

6464
public cleanRawRouteParsed(route: string): object {
6565
let routesWithoutSpaces = route.replace(/ /gm, '');
66-
let testTrailingComma = routesWithoutSpaces.indexOf('},]');
66+
const testTrailingComma = routesWithoutSpaces.indexOf('},]');
6767
if (testTrailingComma !== -1) {
6868
routesWithoutSpaces = routesWithoutSpaces.replace('},]', '}]');
6969
}
7070

7171
routesWithoutSpaces = routesWithoutSpaces.replace(
7272
this.transformAngular8ImportSyntax,
73-
'$1"$3#$5"'
73+
'$1"$4#$6"'
7474
);
7575

7676
return JSON5.parse(routesWithoutSpaces);
@@ -85,7 +85,7 @@ export class RouterParserUtil {
8585

8686
routesWithoutSpaces = routesWithoutSpaces.replace(
8787
this.transformAngular8ImportSyntax,
88-
'$1"$3#$5"'
88+
'$1"$4#$6"'
8989
);
9090

9191
return routesWithoutSpaces;

test/fixtures/todomvc-ng2-simple-routing-standard/src/app/app-routing.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
3+
import { AboutModule } from './about';
34

45
export const APP_ROUTES: Routes = [
5-
{ path: 'about', loadChildren: () => import('./about/about.module').then(m => m.AboutModule) },
6+
{
7+
path: 'about',
8+
loadChildren: (): Promise<AboutModule> =>
9+
import('./about/about.module').then(m => m.AboutModule)
10+
},
611
{ path: '', redirectTo: 'home', pathMatch: 'full' },
712
{ path: '**', redirectTo: 'home', pathMatch: 'full' }
813
];

0 commit comments

Comments
 (0)