Estoy usando Angular 13 y creé un archivo myapp.mainrouting.js e intento declarar loadChildren como se muestra a continuación:
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 }, ]Sin embargo, recibo el siguiente error:
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'Para las importaciones dinámicas, deberá actualizar esto
{ path: 'Supplier', loadChildren: '../Supplier/CustomerApp.SupplierModule#CustomerAppSupplierModule' },A esto:
{ path: 'Supplier', loadChildren: () => import('../Supplier/CustomerApp.SupplierModule').then(x => x.CustomerAppSupplierModule) }, También verifique que en su tsconfig.json tenga esta línea "module": "esnext"
{ ... "compilerOptions": { ... "module": "esnext" ... } }