我已经在已经开发的应用程序上实现了延迟加载,但是在实现之后,它正在加载除Home Page之外的任何其他组件,并且这仅在Home Page中发生。我的根级路由如下:
{path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: '', loadChildren: './views/home/home.module#HomeModule'},
{ path: 'resetpass', loadChildren: './views/resetpass/resetpass.module#ResetpassModule'},
{ path: 'forgotpass', loadChildren: './views/forgotpass/forgot.module#ForgotpassModule'},
{ path: 'signup', loadChildren: './views/signup/signup.module#SignupModule'},
{ path: 'login', loadChildren: './views/login/login.module#LoginModule' },
{ path: 'otp', loadChildren: './views/otp/otp.module#OtpModule'},
{ path: 'school', loadChildren: './views/school/school-home/school-home.module#SchoolhomeModule'},
{ path: 'school/addstudents', loadChildren: './views/school/add-students/add-students.module#AddstudentsModule'},
{ path: 'school/managestudents', loadChildren: './views/school/manage-students/manage-students.module#ManagestudentsModule'},
{ path: 'school/ViewLogsDetails', loadChildren: './views/school/View-Log-Details/logdetails.module#LogdetailsModule'},
{ path: 'school/accountinfo', loadChildren: './views/school/accountinfo/accountinfo.module#AccountinfoModule'},
{ path: 'school/subscribe', loadChildren: './views/school/cals-subscribe/cal-subscribe.module#CalsubscribeModule'},
{ path: 'school/addstaff', loadChildren: './views/school/add-staff/add-staff.module#AddstaffModule'},
{ path: 'school/trans-track/:id', loadChildren: './views/school/trans-track/trans-track.module#TranstrackModule'},
{ path: '**', loadChildren: './views/home/home.module#HomeModule' }
在主页上,这将加载AddstudentsComponent,即使它应该在登录后也可以正常工作,这是AddStudent的路由模块:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AddStudentsComponent } from './add-students.component';
const routes: Routes = [
{ path: '', component: AddStudentsComponent}
];
@NgModule({
exports: [RouterModule],
imports: [RouterModule.forChild(routes)]
})
export class AddstudentsRoutingModule { }
将路径从“”更改为“ school / addstudent”之类的东西后,它将立即加载AddStaff组件。
整个应用程序运行良好,直到将Module放入每个组件级别。不知道该如何应对。
答案 0 :(得分:0)
我在app.module.ts中包含了惰性加载模块,如下所示:
import { AddstaffModule } from './views/school/add-staff/add-staff.module';
但是我对其他组件级模块没有做同样的事情。因此,该应用程序运行不佳。
我现在要做的是从app.module.ts中删除组件级模块,就像该行已被删除一样:
import { AddstaffModule } from './views/school/add-staff/add-staff.module';
而且,它变得一致。