Template strings (or string concatenation) doesn't work for the loadChildren string
PEsteves8 opened this issue · comments
Doing something like this:
loadChildren: './protected/dashboard/' + 'dashboard.module#nmDashboardModule'
or
loadChildren: `./protected/dashboard/dashboard.module#nmDashboardModule`
breaks compilation.
Getting this on the console output:
TS2345: Argument of type '({ path: string; redirectTo: string; pathMatch: string; } | { path: string; loadChildren: () => t...' is not assignable to parameter of type 'Route[]'.
Type '{ path: string; redirectTo: string; pathMatch: string; } | { path: string; loadChildren: () => ty...' is not assignable to type 'Route'.
Type '{ path: string; loadChildren: () => string; canLoad: typeof AuthGuard[]; }' is not assignable to type 'Route'.
Types of property 'loadChildren' are incompatible.
Type '() => string' is not assignable to type 'LoadChildren'.
Type '() => string' is not assignable to type 'LoadChildrenCallback'.
Type 'string' is not assignable to type 'Type<any> | NgModuleFactory<any> | Promise<Type<any>> | Observable<Type<any>>'.
I've been trying to generate the loadChildren path dynamically using a few variables.
Something like this:
let specialRoute = "./pathSection1/pathSection2";
loadChildren: `${specialRoute}/someModule.module#someModule`
This seems to be allowed with the angular cli / ngtools loader
The loader does not execute your code, therefore it can't evaluate what that expression will return. You don't need this loader if you're using the ngtools loader.