Skip to content

Commit

Permalink
feat: lazy load home page and guides
Browse files Browse the repository at this point in the history
Relates to #176
  • Loading branch information
Splaktar committed Jan 14, 2020
1 parent 0d5c311 commit 7a099d4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
12 changes: 1 addition & 11 deletions src/app/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {NgModule} from '@angular/core';
import {LocationStrategy, PathLocationStrategy} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {RouterModule} from '@angular/router';
import {MatNativeDateModule} from '@angular/material/core';
import {ExampleModule} from '@angular/components-examples';

import {MaterialDocsApp} from './material-docs-app';
import {HomepageModule} from './pages/homepage';
import {MATERIAL_DOCS_ROUTES} from './routes';
import {ComponentListModule} from './pages/component-list';
import {ComponentViewerModule} from './pages/component-viewer/component-viewer';
Expand All @@ -25,12 +23,8 @@ import {NavBarModule} from './shared/navbar';
import {ThemeStorage} from './shared/theme-picker/theme-storage/theme-storage';
import {GuideItems} from './shared/guide-items/guide-items';
import {DocumentationItems} from './shared/documentation-items/documentation-items';
import {GuideListModule} from './pages/guide-list';
import {GuideViewerModule} from './pages/guide-viewer';
import {DocViewerModule} from './shared/doc-viewer/doc-viewer-module';
import {
CanActivateComponentSidenav
} from './pages/component-sidenav/component-sidenav-can-load-guard';
import {CanActivateComponentSidenav} from './pages/component-sidenav/component-sidenav-can-load-guard';
import {HttpClientModule} from '@angular/common/http';
import {GaService} from './shared/ga/ga';

Expand All @@ -41,7 +35,6 @@ import {GaService} from './shared/ga/ga';
ExampleModule,
FormsModule,
HttpClientModule,
MatNativeDateModule,
RouterModule.forRoot(MATERIAL_DOCS_ROUTES, {
scrollPositionRestoration: 'enabled',
anchorScrolling: 'enabled',
Expand All @@ -54,9 +47,6 @@ import {GaService} from './shared/ga/ga';
ComponentViewerModule,
DocViewerModule,
FooterModule,
GuideListModule,
GuideViewerModule,
HomepageModule,
NavBarModule,
StackBlitzButtonModule,
SvgViewerModule,
Expand Down
5 changes: 3 additions & 2 deletions src/app/pages/guide-list/guide-list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component, NgModule, OnInit} from '@angular/core';
import {GuideItems} from '../../shared/guide-items/guide-items';
import {MatListModule} from '@angular/material/list';
import {RouterModule} from '@angular/router';
import {RouterModule, Routes} from '@angular/router';
import {FooterModule} from '../../shared/footer/footer';
import {CommonModule} from '@angular/common';
import {ComponentPageTitle} from '../page-title/page-title';
Expand All @@ -19,9 +19,10 @@ export class GuideList implements OnInit {
}
}

const routes: Routes = [ {path : '', component : GuideList} ];

@NgModule({
imports: [MatListModule, RouterModule, FooterModule, CommonModule],
imports: [CommonModule, MatListModule, FooterModule, RouterModule.forChild(routes)],
exports: [GuideList],
declarations: [GuideList],
providers: [GuideItems, ComponentPageTitle],
Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/guide-viewer/guide-viewer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, NgModule, OnInit} from '@angular/core';
import {ActivatedRoute, RouterModule, Router} from '@angular/router';
import {ActivatedRoute, Router, RouterModule, Routes} from '@angular/router';
import {GuideItem, GuideItems} from '../../shared/guide-items/guide-items';
import {FooterModule} from '../../shared/footer/footer';
import {DocViewerModule} from '../../shared/doc-viewer/doc-viewer-module';
Expand Down Expand Up @@ -37,8 +37,10 @@ export class GuideViewer implements OnInit {
}
}

const routes: Routes = [ {path : '', component : GuideViewer} ];

@NgModule({
imports: [DocViewerModule, FooterModule, RouterModule, TableOfContentsModule],
imports: [DocViewerModule, FooterModule, TableOfContentsModule, RouterModule.forChild(routes)],
exports: [GuideViewer],
declarations: [GuideViewer],
providers: [GuideItems, ComponentPageTitle],
Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/homepage/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component, NgModule, OnInit} from '@angular/core';
import {SvgViewerModule} from '../../shared/svg-viewer/svg-viewer';
import {MatButtonModule} from '@angular/material/button';
import {FooterModule} from '../../shared/footer/footer';
import {RouterModule} from '@angular/router';
import {RouterModule, Routes} from '@angular/router';
import {ComponentPageTitle} from '../page-title/page-title';

@Component({
Expand All @@ -20,8 +20,10 @@ export class Homepage implements OnInit {
}
}

const routes: Routes = [ {path : '', component : Homepage} ];

@NgModule({
imports: [SvgViewerModule, MatButtonModule, FooterModule, RouterModule],
imports: [SvgViewerModule, MatButtonModule, FooterModule, RouterModule.forChild(routes)],
exports: [Homepage],
declarations: [Homepage],
})
Expand Down
22 changes: 13 additions & 9 deletions src/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {Homepage} from './pages/homepage';
import {ComponentList} from './pages/component-list';
import {GuideList} from './pages/guide-list';
import {Routes} from '@angular/router';
import {
ComponentApi,
Expand All @@ -10,19 +8,25 @@ import {
} from './pages/component-viewer/component-viewer';
import {ComponentCategoryList} from './pages/component-category-list/component-category-list';
import {ComponentSidenav} from './pages/component-sidenav/component-sidenav';
import {
CanActivateComponentSidenav
} from './pages/component-sidenav/component-sidenav-can-load-guard';
import {GuideViewer} from './pages/guide-viewer';
import {CanActivateComponentSidenav} from './pages/component-sidenav/component-sidenav-can-load-guard';

export const MATERIAL_DOCS_ROUTES: Routes = [
{path: '', component: Homepage, pathMatch: 'full', data: {}},
{
path: '', pathMatch: 'full',
loadChildren: () => import('./pages/homepage').then(m => m.HomepageModule)
},
{path: 'categories', redirectTo: '/components/categories'},
{path: 'guides', component: GuideList, data: {}},
{
path: 'guides',
loadChildren: () => import('./pages/guide-list').then(m => m.GuideListModule)
},
// Since https://github.com/angular/components/pull/9574, the cdk-table guide became the overview
// document for the cdk table. To avoid any dead / broken links, we redirect to the new location.
{path: 'guide/cdk-table', redirectTo: '/cdk/table/overview'},
{path: 'guide/:id', component: GuideViewer, data: {}},
{
path: 'guide/:id',
loadChildren: () => import('./pages/guide-viewer').then(m => m.GuideViewerModule)
},
{
path: ':section',
canActivate: [CanActivateComponentSidenav],
Expand Down

0 comments on commit 7a099d4

Please sign in to comment.