ng-router-loader icon indicating copy to clipboard operation
ng-router-loader copied to clipboard

loadChildren: ()=> './myroute/blah/blah' is not assignable to type Route

Open FieldMarshallVague opened this issue 7 years ago • 9 comments

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.

FieldMarshallVague avatar Jul 03 '17 14:07 FieldMarshallVague

+1

kirill-onufrienko-db avatar Jul 18 '17 06:07 kirill-onufrienko-db

+1

EvanBurbidge avatar Jul 20 '17 11:07 EvanBurbidge

+1

amitrke avatar Aug 08 '17 17:08 amitrke

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 avatar Aug 10 '17 16:08 shlomiassaf

@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.

entith avatar Oct 12 '17 14:10 entith

Assigning lambda will also break AoT... So just avoid it?

lanovoy avatar Jan 08 '18 08:01 lanovoy

I'm having the same issue... Also, passing a valid string isn't working for me either...

ironicnet avatar Feb 15 '18 19:02 ironicnet

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' } ];

hectorolan avatar Feb 24 '18 01:02 hectorolan

image

i am facing problem in loadchildren value asign. i can use angular version = 13.1.0 typescript = 4.5.2

dchirag005 avatar Jan 06 '22 12:01 dchirag005