I am developing somewhat large application using angular 5 with several modules. Each modules has loaded as lazy loading mechanism of Angular 5. I am sharing components between those modules and they are working fine. But I am having an issue with loading module root as follows.
App module routing
export const routes: Routes = [
{ path: '', component: MenuComponent },
{ path: 'logout', component: LogoutComponent },
{ path: 'admin', loadChildren: 'app/modules/admin/admin.module#AdminModule' },
{ path: 'sample', loadChildren: 'app/modules/sample/sample.module#SampleModule' },
{ path: 'membership', loadChildren: 'app/modules/membership/membership.module#MembershipModule' },
{ path: 'class', loadChildren: 'app/modules/class/class.module#ClassModule' },
{ path: '**', component: PageNotFoundComponent }
];
I am sharing components inside ClassModule, in AdminModule.
Class Module
@NgModule({
imports: [
CommonModule,
SharedModule,
ClassRoutingModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
ClassRoutingComponents,
ClassHomeComponent,
ClassListComponent,
ClassCalendarComponent,
AddNewCalssComponent,
ClassScheduleComponent
],
exports: [
ClassRoutingComponents,
ClassHomeComponent,
ClassListComponent,
AddNewCalssComponent,
ClassScheduleComponent
],
providers: [
]
})
export class ClassModule {}
AdminModule has imported ClassModule as follows.
@NgModule({
imports: [
CommonModule,
SharedModule,
FormsModule,
ClassModule
],
declarations: [
AdminRoutingComponents,
.......
],
providers:
[
AdminService,
]
})
export class AdminModule { }
Class Routing
const routes: Routes = [
{ path: '', component: ClassHomeComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
Admin Routing
const routes: Routes = [
{ path: '', component: AdminHomeComponent },
{ path: 'settings', component: SettingsComponent },
...
}
Every components has shared works fine but my problem is when I am routing to http://localhost:4200/admin it loades ClassHomeComponent but it must load AdminHomeComponent