Created
July 31, 2019 20:27
-
-
Save NetanelBasal/49a456e94d6beccff7d7f74f9336a1c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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