Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created Jul 31, 2019
Embed
What would you like to do?
@Injectable({ providedIn: 'root' })
export class AppPreloadingStrategy implements PreloadingStrategy {
constructor(private userQuery: UserQuery) {
}
preload(route: Route, load: () => Observable<any>): Observable<any> {
return this.userQuery.hasFlags(route.data.flags) ? load() : of(false);
}
}
const routes: Routes = [
{
path: 'bar',
loadChildren: () => import('./bar/bar.module').then(m => m.BarModule),
data: {
flags: 'a'
},
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { preloadingStrategy: AppPreloadingStrategy })],
exports: [RouterModule]
})
export class AppRoutingModule {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment