Reputation: 175
I am using angular 8. Can I make a custom middleware for checking network speed and local storage checking before any component load. Can you please suggest me how to do it?
Upvotes: 0
Views: 2120
Reputation: 524
Try using resolvers
which is called before any component load like this-
custom.resolver.ts
import {
Resolve,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Router
} from '@angular/router';
import { Inject } from '@angular/core';
export class ActiveResolver implements Resolve<any> {
constructor() {}
resolve(_route: ActivatedRouteSnapshot, _rstate: RouterStateSnapshot) {
<-- your custom logic for speed -->
}
}
In your app.module.ts
RouterModule.forRoot([
{
path: 'yourcomponent',
component: yourcomponent,
pathMatch: 'full',
resolve: { ar: ActiveResolver }
}]
Upvotes: 1