Home

Awesome

mgechev

<p align="center"> <img src="https://github.com/mgechev/ngx-hover-preload/blob/master/assets/ngx-hover-preload.png?raw=true" width="200px"> </div>

ngx-hover-preload

This package exports a PreloadingStrategy, which will preload a lazy-loaded route on mouse over a corresponding router link.

Alternatives

Other preloading strategies:

Example

Example is available here.

Usage

Install the module:

yarn add ngx-hover-preload

Standalone

Configure your app with the correct providers:

bootstrapApplication(AppComponent, {
  providers: [hoverPrefetchProviders, provideRouter(routes, withPreloading(HoverPreloadStrategy))]
});

Make sure you import the HoverPrefetchLinkDirective anywhere you want to enable prefetching.

In case you want to disable prefetching for a particular route specify:

{
  path: 'foo',
  data: {
    preload: false
  }
}

NgModules

Import the HoverPreloadModule in your AppModule and your lazy-loaded modules to ensure the required directives are available:

// ...
import { HoverPreloadModule } from 'ngx-hover-preload';

@NgModule({
  declarations: [
    // ...
  ],
  imports: [
    // ...
    HoverPreloadModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Make sure you import the HoverPreloadModule in all lazy-loaded modules in which you want to have this functionality available

Don't forget to set the HoverPreloadStrategy as your preloadStrategy:

// ...
import { HoverPreloadStrategy } from 'ngx-hover-preload';

@NgModule({
  // ...
  imports: [RouterModule.forRoot(routes, { preloadingStrategy: HoverPreloadStrategy })],
})
export class AppModule {} // or AppRoutingModule

License

MIT