Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created July 31, 2019 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/49a456e94d6beccff7d7f74f9336a1c5 to your computer and use it in GitHub Desktop.
Save NetanelBasal/49a456e94d6beccff7d7f74f9336a1c5 to your computer and use it in GitHub Desktop.
@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