ng-router-loader
ng-router-loader copied to clipboard
loadChildren: ()=> './myroute/blah/blah' is not assignable to type Route
Hi there,
I'm getting the above error when I'm configuring my routes. I'm following the docs exactly as described, but the lamba expression fails the Typescript intellisense (in VS2015) and the build process does not complete.
I'm using ng-router-loader 2.1.0 and angular 4.1.2 (angular/router 4.1.2).
The specific error is this:
Type '{ path: string; loadChildren: () => string; }' is not assignable to type 'Route'.
My code is basically this: { path: 'sales', loadChildren: './sales.module#SalesModule' },
I realise this isn't likely to be ng-router-loader's problem, but that is the specific format the documentation says to use, so I'm starting here :)
Do I need to match a specific version of angular or similar?
Thanks.
+1
+1
+1
Hi
This is not clear to me... The loadChildren type is:
export type LoadChildren = string | LoadChildrenCallback;
Si there is no violation there...
Is it specific to VS2015? What's the TS version?
@shlomiassaf According to the current Angular documentation, LoadChildrenCallback
is a function that returns one of Type<any>| NgModuleFactory<any>| Promise<Type<any>>| Observable<Type<any>>
, not a string.
type LoadChildrenCallback = () =>
Type<any>| NgModuleFactory<any>| Promise<Type<any>>| Observable<Type<any>>;
Assigning loadChildren
a string works, but assigning it a callback function that returns a string (as per your documentation) does not work.
Assigning lambda will also break AoT... So just avoid it?
I'm having the same issue... Also, passing a valid string isn't working for me either...
I had the same issue, I am on Angular 5.2.1. Try to explicit declare the variable route:
import { RouterModule, Route } from '@angular/router';
then update the variable that you are using for example:
var routes: Route[] = [ { path: 'main', loadChildren: './components/main/main.module#MainModule' }, { path: '', redirectTo: 'main', pathMatch: 'full' }, { path: '**', redirectTo: 'main' } ];
i am facing problem in loadchildren value asign. i can use angular version = 13.1.0 typescript = 4.5.2