I have a module named index.module, then set a router to lazy load it.
The router component is like a layout component which contains some other components, for example header, footer.
The problem is when I used the hmr-module-helper to wrap my index.module, everytime I modify the files in other components( not the route component ), HMR didn't work correctly, it replaced the changed files but page content still stay no change.
here is my code.
import { NgModule, NgModuleRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IndexRoutingModule } from './index-routing.module';
import { IndexLayoutComponent } from '../../components/index/common/index-layout/index-layout.component';
import { HomePageComponent } from '../../components/index/home-page/home-page.component';
import { IndexHeaderComponent } from '../../components/index/common/index-header/index-header.component';
import { IndexFooterComponent } from '../../components/index/common/index-footer/index-footer.component';
import { HmrModuleHelper } from 'src/app/hmr-module-helper';
@NgModule({
declarations: [
IndexLayoutComponent,
HomePageComponent,
IndexHeaderComponent,
IndexFooterComponent
],
imports: [CommonModule, IndexRoutingModule]
})
export class IndexModule {
constructor(moduleRef: NgModuleRef<IndexModule>) {
HmrModuleHelper.enableHmrRouterNgModule(module, moduleRef);
}
}
HmrModuleHelper.enableHmrNodeModule(module);
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { IndexLayoutComponent } from 'src/app/components/index/common/index-layout/index-layout.component';
import { HomePageComponent } from 'src/app/components/index/home-page/home-page.component';
const routes: Routes = [
{
path: '',
component: IndexLayoutComponent,
children: [
{
path: 'index',
component: HomePageComponent
}
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class IndexRoutingModule {}
<app-index-header></app-index-header>
<router-outlet></router-outlet>
<app-index-footer></app-index-footer>