Ich benutze angular-CLI und Lazyloader für das Routing.Lazyloader funktioniert nicht auf AOT Produktionsmodus angular-cli
ng serve
funktioniert für mich, aber nach dem Erstellen des Projekts als Produktionsmodus, dann funktioniert es überhaupt nicht.
Hier ist meine app.routing.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { MainComponent } from './main/main.component';
import { AuthGuard } from './core/guards/index';
//Layouts
import { LoginComponent } from './login/login.component';
export const routes: Routes = [
{
path: 'login',
component: LoginComponent
},
{
path: '',
component: MainComponent,
children: [
{
path: '',
loadChildren: './main/main.module#MainModule'
}
],
canActivate: [AuthGuard]
},{
path: '**',
redirectTo: 'login'
}
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
Und das ist Fehler, den ich nach ng build --prod --aot
oder ng serve --prod
bekam.
ERROR Error: Uncaught (in promise): Error: Cannot find module './app/main/main.module'.
Error: Cannot find module './app/main/main.module'.
at t (main.1f6da18….bundle.js:1)
at t.loadAndCompile (vendor.490f84a….bundle.js:379)
at t.load (vendor.490f84a….bundle.js:379)
at t.loadModuleFactory (vendor.490f84a….bundle.js:428)
at t.load (vendor.490f84a….bundle.js:428)
at e.project (vendor.490f84a….bundle.js:428)
at e.XO5T.e._tryNext (vendor.490f84a….bundle.js:897)
at e.XO5T.e._next (vendor.490f84a….bundle.js:897)
at e.next (vendor.490f84a….bundle.js:897)
at e.RRVv.e._subscribe (vendor.490f84a….bundle.js:736)
at t (main.1f6da18….bundle.js:1)
at t.loadAndCompile (vendor.490f84a….bundle.js:379)
at t.load (vendor.490f84a….bundle.js:379)
at t.loadModuleFactory (vendor.490f84a….bundle.js:428)
at t.load (vendor.490f84a….bundle.js:428)
at e.project (vendor.490f84a….bundle.js:428)
at e.XO5T.e._tryNext (vendor.490f84a….bundle.js:897)
at e.XO5T.e._next (vendor.490f84a….bundle.js:897)
at e.next (vendor.490f84a….bundle.js:897)
at e.RRVv.e._subscribe (vendor.490f84a….bundle.js:736)
at u (polyfills.1e19b2c….bundle.js:43)
at u (polyfills.1e19b2c….bundle.js:43)
at polyfills.1e19b2c….bundle.js:43
at t.invokeTask (polyfills.1e19b2c….bundle.js:36)
at Object.onInvokeTask (vendor.490f84a….bundle.js:365)
at t.invokeTask (polyfills.1e19b2c….bundle.js:36)
at r.runTask (polyfills.1e19b2c….bundle.js:36)
at o (polyfills.1e19b2c….bundle.js:36)
Hier ist Screenshot der Browser-Konsole.
Was ist falsch an meiner Routing-Konfiguration? PP: ng serve
arbeitet ohne Fehler.
Was passiert, wenn Sie ng Build ausführen --prod --oot false –
Vielen Dank für Ihre Antwort. Ich habe das ausprobiert und auf dem Apache Server getestet. es heißt 'Uncaught TypeError: Kann die Eigenschaft 'call' von undefined nicht lesen. Vielleicht gibt es ein Problem mit meinem Code? – blackiii
Es gab ein Problem mit meinem Code. 'loadChildren: './main/main.module.ts # MainModule'' Ich habe das als' loadChildren:' geändert./main/main.module # MainModule''. Und 'ng build --prod --aot false' funktioniert gut. Was stimmt nicht mit AoT? – blackiii