Skip to content

Commit c5031f8

Browse files
author
Your Name
committed
Angular Router Course
1 parent c0882e9 commit c5031f8

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/app/app-routing.module.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {LoginComponent} from './login/login.component';
44
import {AboutComponent} from './about/about.component';
55
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
66
import {CanLoadAuthGuard} from './services/can-load-auth.guard';
7+
import {CustomPreloadingStrategy} from './services/custom-preloading.strategy';
78

89

910
const routes: Routes = [
@@ -15,8 +16,11 @@ const routes: Routes = [
1516
{
1617
path: "courses",
1718
loadChildren: () => import('./courses/courses.module')
18-
.then(m => m.CoursesModule)
19+
.then(m => m.CoursesModule),
1920
// canLoad: [CanLoadAuthGuard]
21+
data: {
22+
preload: false
23+
}
2024
},
2125
{
2226
path: "login",
@@ -37,12 +41,13 @@ const routes: Routes = [
3741
imports: [
3842
RouterModule.forRoot(
3943
routes, {
40-
preloadingStrategy: PreloadAllModules
44+
preloadingStrategy: CustomPreloadingStrategy
4145
})
4246
],
4347
exports: [RouterModule],
4448
providers: [
45-
CanLoadAuthGuard
49+
CanLoadAuthGuard,
50+
CustomPreloadingStrategy
4651
]
4752
})
4853
export class AppRoutingModule {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Injectable} from '@angular/core';
2+
import {PreloadingStrategy, Route} from '@angular/router';
3+
import {Observable, of} from 'rxjs';
4+
5+
6+
@Injectable()
7+
export class CustomPreloadingStrategy implements PreloadingStrategy {
8+
9+
10+
preload(route: Route, load: () => Observable<any>): Observable<any> {
11+
if (route.data["preload"]) {
12+
return load();
13+
}
14+
else {
15+
of(null);
16+
}
17+
}
18+
19+
}

0 commit comments

Comments
 (0)