类型 'string' 不可分配给类型 'LoadChildrenCallback
Type 'string' is not assignable to type 'LoadChildrenCallback
我正在使用 Angular 13
并创建了一个 myapp.mainrouting.js
文件并尝试声明 loadChildren
如下:
import {CustomerAppHomeComponent} from "../Home/CustomerApp.HomeComponent";
import {Routes} from "@angular/router";
export const MainRoutes: Routes = [
{ path: 'Home', component: CustomerAppHomeComponent },
{ path: 'Supplier', loadChildren: '../Supplier/CustomerApp.SupplierModule#CustomerAppSupplierModule' },
{ path: '', component: CustomerAppHomeComponent },
]
但是,我遇到以下错误:
error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback | undefined'.
8 { path: 'Supplier', loadChildren: '../Supplier/CustomerApp.SupplierModule#CustomerAppSupplierModule' },
~~~~~~~~~~~~
node_modules/@angular/router/router.d.ts:1998:5
1998 loadChildren?: LoadChildren;
~~~~~~~~~~~~
The expected type comes from property 'loadChildren' which is declared here on type 'Route'
对于动态导入,您需要更新此项
{ path: 'Supplier', loadChildren: '../Supplier/CustomerApp.SupplierModule#CustomerAppSupplierModule' },
为此:
{
path: 'Supplier',
loadChildren: () => import('../Supplier/CustomerApp.SupplierModule').then(x => x.CustomerAppSupplierModule)
},
还要仔细检查 tsconfig.json 中是否有这一行 "module": "esnext"
{
...
"compilerOptions": {
...
"module": "esnext"
...
}
}
我正在使用 Angular 13
并创建了一个 myapp.mainrouting.js
文件并尝试声明 loadChildren
如下:
import {CustomerAppHomeComponent} from "../Home/CustomerApp.HomeComponent";
import {Routes} from "@angular/router";
export const MainRoutes: Routes = [
{ path: 'Home', component: CustomerAppHomeComponent },
{ path: 'Supplier', loadChildren: '../Supplier/CustomerApp.SupplierModule#CustomerAppSupplierModule' },
{ path: '', component: CustomerAppHomeComponent },
]
但是,我遇到以下错误:
error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback | undefined'.
8 { path: 'Supplier', loadChildren: '../Supplier/CustomerApp.SupplierModule#CustomerAppSupplierModule' },
~~~~~~~~~~~~
node_modules/@angular/router/router.d.ts:1998:5
1998 loadChildren?: LoadChildren;
~~~~~~~~~~~~
The expected type comes from property 'loadChildren' which is declared here on type 'Route'
对于动态导入,您需要更新此项
{ path: 'Supplier', loadChildren: '../Supplier/CustomerApp.SupplierModule#CustomerAppSupplierModule' },
为此:
{
path: 'Supplier',
loadChildren: () => import('../Supplier/CustomerApp.SupplierModule').then(x => x.CustomerAppSupplierModule)
},
还要仔细检查 tsconfig.json 中是否有这一行 "module": "esnext"
{
...
"compilerOptions": {
...
"module": "esnext"
...
}
}