File tree 2 files changed +27
-3
lines changed
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import {LoginComponent} from './login/login.component';
4
4
import { AboutComponent } from './about/about.component' ;
5
5
import { PageNotFoundComponent } from './page-not-found/page-not-found.component' ;
6
6
import { CanLoadAuthGuard } from './services/can-load-auth.guard' ;
7
+ import { CustomPreloadingStrategy } from './services/custom-preloading.strategy' ;
7
8
8
9
9
10
const routes : Routes = [
@@ -15,8 +16,11 @@ const routes: Routes = [
15
16
{
16
17
path : "courses" ,
17
18
loadChildren : ( ) => import ( './courses/courses.module' )
18
- . then ( m => m . CoursesModule )
19
+ . then ( m => m . CoursesModule ) ,
19
20
// canLoad: [CanLoadAuthGuard]
21
+ data : {
22
+ preload : false
23
+ }
20
24
} ,
21
25
{
22
26
path : "login" ,
@@ -37,12 +41,13 @@ const routes: Routes = [
37
41
imports : [
38
42
RouterModule . forRoot (
39
43
routes , {
40
- preloadingStrategy : PreloadAllModules
44
+ preloadingStrategy : CustomPreloadingStrategy
41
45
} )
42
46
] ,
43
47
exports : [ RouterModule ] ,
44
48
providers : [
45
- CanLoadAuthGuard
49
+ CanLoadAuthGuard ,
50
+ CustomPreloadingStrategy
46
51
]
47
52
} )
48
53
export class AppRoutingModule {
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments