Merge pull request #4386 from tsiegleauq/preload-modules

Preloads modules on site component
This commit is contained in:
Sean 2019-02-22 10:19:56 +01:00 committed by GitHub
commit 497a3ec71d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import { LoginLegalNoticeComponent } from './site/login/components/login-legal-n
import { LoginPrivacyPolicyComponent } from './site/login/components/login-privacy-policy/login-privacy-policy.component';
import { ResetPasswordComponent } from './site/login/components/reset-password/reset-password.component';
import { ResetPasswordConfirmComponent } from './site/login/components/reset-password-confirm/reset-password-confirm.component';
import { AppPreloader } from './shared/utils/app-preloader';
/**
* Global app routing
@ -29,7 +30,8 @@ const routes: Routes = [
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
imports: [RouterModule.forRoot(routes, { preloadingStrategy: AppPreloader })],
exports: [RouterModule],
providers: [AppPreloader]
})
export class AppRoutingModule {}

View File

@ -0,0 +1,27 @@
import { PreloadingStrategy, Route } from '@angular/router';
import { Observable, of } from 'rxjs';
/**
* Custom preload strategy class
*
* @example
* ```
* {
* path: 'agenda',
* loadChildren: './agenda/agenda.module#AgendaModule',
* data: { preload: true }
* }
* ```
*/
export class AppPreloader implements PreloadingStrategy {
/**
* Custom preload function.
* Can be add to routes as data argument.
*
* @param route The route to load
* @param load The load function
*/
public preload(route: Route, load: Function): Observable<any> {
return route.data && route.data.preload ? load() : of(null);
}
}

View File

@ -2,7 +2,6 @@ import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SiteComponent } from './site.component';
import { AuthGuard } from '../core/core-services/auth-guard.service';
/**
@ -17,43 +16,53 @@ const routes: Routes = [
children: [
{
path: '',
loadChildren: './common/common.module#CommonModule'
loadChildren: './common/common.module#CommonModule',
data: { preload: true }
},
{
path: 'agenda',
loadChildren: './agenda/agenda.module#AgendaModule'
loadChildren: './agenda/agenda.module#AgendaModule',
data: { preload: true }
},
{
path: 'assignments',
loadChildren: './assignments/assignments.module#AssignmentsModule'
loadChildren: './assignments/assignments.module#AssignmentsModule',
data: { preload: true }
},
{
path: 'mediafiles',
loadChildren: './mediafiles/mediafiles.module#MediafilesModule'
loadChildren: './mediafiles/mediafiles.module#MediafilesModule',
data: { preload: true }
},
{
path: 'motions',
loadChildren: './motions/motions.module#MotionsModule'
loadChildren: './motions/motions.module#MotionsModule',
data: { preload: true }
},
{
path: 'settings',
loadChildren: './config/config.module#ConfigModule'
loadChildren: './config/config.module#ConfigModule',
data: { preload: true }
},
{
path: 'users',
loadChildren: './users/users.module#UsersModule'
loadChildren: './users/users.module#UsersModule',
data: { preload: true }
},
{
path: 'tags',
loadChildren: './tags/tag.module#TagModule'
loadChildren: './tags/tag.module#TagModule',
data: { preload: true }
},
{
path: 'history',
loadChildren: './history/history.module#HistoryModule'
loadChildren: './history/history.module#HistoryModule',
data: { preload: true }
},
{
path: 'projectors',
loadChildren: './projector/projector.module#ProjectorModule'
loadChildren: './projector/projector.module#ProjectorModule',
data: { preload: true }
}
],
canActivateChild: [AuthGuard]