Skip to content

Commit 248e0cc

Browse files
committed
mathisGarberg#1 - Added lazy loading of about module
1 parent 4c29112 commit 248e0cc

17 files changed

+160
-18
lines changed

package-lock.json

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/app-routing.module.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
33

4+
import { ContentLayoutComponent } from './layouts/content-layout/content-layout.component';
5+
6+
47
const routes: Routes = [
5-
// Fallback when no prior routes is matched
6-
{ path: '**', redirectTo: '', pathMatch: 'full' }
8+
{
9+
path: '',
10+
component: ContentLayoutComponent,
11+
children: [
12+
{
13+
path: 'about',
14+
loadChildren: './modules/about/about.module#AboutModule'
15+
}
16+
]
17+
},
18+
// Fallback when no prior routes is matched
19+
{ path: '**', redirectTo: '', pathMatch: 'full' }
720
];
821

922
@NgModule({
1023
imports: [RouterModule.forRoot(routes, {useHash: true})],
1124
exports: [RouterModule],
1225
providers: []
1326
})
14-
export class AppRoutingModule { }
27+
export class AppRoutingModule { }

src/app/app.component.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<app-nav></app-nav>
21
<router-outlet></router-outlet>
3-
<app-footer></app-footer>

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { HomeModule } from './modules/home/home.module';
88

99
import { AppComponent } from './app.component';
1010
import { AppRoutingModule } from './app-routing.module';
11+
import { ContentLayoutComponent } from './layouts/content-layout/content-layout.component';
1112

1213
@NgModule({
1314
declarations: [
14-
AppComponent
15+
AppComponent,
16+
ContentLayoutComponent
1517
],
1618
imports: [
1719
// angular

src/app/core/app-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const config: any = {
22
API_URL: 'assets/api'
3-
};
3+
};

src/app/layouts/content-layout/content-layout.component.css

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="wrapper">
2+
<app-nav></app-nav>
3+
<router-outlet></router-outlet>
4+
<app-footer></app-footer>
5+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ContentLayoutComponent } from './content-layout.component';
4+
5+
describe('ContentLayoutComponent', () => {
6+
let component: ContentLayoutComponent;
7+
let fixture: ComponentFixture<ContentLayoutComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ ContentLayoutComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ContentLayoutComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-content-layout',
5+
templateUrl: './content-layout.component.html',
6+
styleUrls: ['./content-layout.component.css']
7+
})
8+
export class ContentLayoutComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit() {
13+
}
14+
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NgModule } from '@angular/core';
2+
import { Routes, RouterModule } from '@angular/router';
3+
4+
import { AboutComponent } from './pages/about/about.component';
5+
6+
const routes: Routes = [
7+
{
8+
path: '',
9+
component: AboutComponent
10+
}
11+
];
12+
13+
@NgModule({
14+
imports: [RouterModule.forChild(routes)],
15+
exports: [RouterModule]
16+
})
17+
export class AboutRoutingModule { }

src/app/modules/about/about.module.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { NgModule } from '@angular/core';
2+
3+
import { SharedModule } from '@app/shared';
4+
5+
import { AboutRoutingModule } from './about-routing.module';
6+
import { AboutComponent } from './pages/about/about.component';
7+
8+
@NgModule({
9+
declarations: [AboutComponent],
10+
imports: [
11+
AboutRoutingModule,
12+
13+
SharedModule
14+
]
15+
})
16+
export class AboutModule { }

src/app/modules/about/pages/about/about.component.css

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>
2+
about works!
3+
</p>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { AboutComponent } from './about.component';
4+
5+
describe('AboutComponent', () => {
6+
let component: AboutComponent;
7+
let fixture: ComponentFixture<AboutComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ AboutComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(AboutComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-about',
5+
templateUrl: './about.component.html',
6+
styleUrls: ['./about.component.css']
7+
})
8+
export class AboutComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit() {
13+
}
14+
15+
}

src/app/shared/layout/layout.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { RouterModule } from '@angular/router';
24

35
import { NavComponent } from './nav/nav.component';
46
import { FooterComponent } from './footer/footer.component';
@@ -9,12 +11,13 @@ import { FooterComponent } from './footer/footer.component';
911
FooterComponent
1012
],
1113
imports: [
12-
14+
CommonModule,
15+
RouterModule
1316
],
1417
exports: [
1518
NavComponent,
1619
FooterComponent
1720
],
1821
providers: [],
1922
})
20-
export class LayoutModule { }
23+
export class LayoutModule { }

src/app/shared/layout/nav/nav.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { environment } from '@env/environment';
88
styleUrls: ['./nav.component.scss']
99
})
1010
export class NavComponent implements OnInit {
11-
12-
version = environment.version;
13-
14-
constructor() { }
1511

16-
ngOnInit(): void { }
12+
version = environment.version;
13+
14+
constructor() { }
15+
16+
ngOnInit(): void { }
1717
}

0 commit comments

Comments
 (0)