Based on ngx-hover-preload
This package exports:
PreloadingStrategy
, which will preload a lazy-loaded route on mouse over a corresponding router link.PreloadOnDemandService
, which can be used to directly load a module that contains a given route path.
- Install the package:
npm install --save ngx-hover-preload-v2
- Import the
HoverPreloadModule
into yourAppModule
AND your lazy-loaded modules to ensure the link hover directive is available:
// ...
import { HoverPreloadModule } from 'ngx-hover-preload-v2';
@NgModule({
declarations: [
// ...
],
imports: [
// ...
HoverPreloadModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
- Set your
RouteModule
preload strategy toHoverPreloadStrategy
:
// ...
import { HoverPreloadStrategy } from 'ngx-hover-preload-v2';
@NgModule({
// ...
imports: [RouterModule.forRoot(routes, { preloadingStrategy: HoverPreloadStrategy })],
})
export class AppModule {} // or AppRoutingModule
MIT