Skip to content

Commit e327fd6

Browse files
committed
add a lazy route
1 parent f1c8a3c commit e327fd6

12 files changed

+107
-14
lines changed

src/app/app-routing.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
3+
import { EmptyComponent } from './empty/empty.component';
34

4-
const routes: Routes = [];
5+
const routes: Routes = [
6+
{ path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule'},
7+
{ path: '', component: EmptyComponent},
8+
];
59

610
@NgModule({
711
imports: [RouterModule.forRoot(routes)],

src/app/app.component.html

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,5 @@ <h1>
55
</h1>
66
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
77
</div>
8-
<h2>Here are some links to help you start: </h2>
9-
<ul>
10-
<li>
11-
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
12-
</li>
13-
<li>
14-
<h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2>
15-
</li>
16-
<li>
17-
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
18-
</li>
19-
</ul>
208

219
<router-outlet></router-outlet>

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { NgModule } from '@angular/core';
33

44
import { AppRoutingModule } from './app-routing.module';
55
import { AppComponent } from './app.component';
6+
import { EmptyComponent } from './empty/empty.component';
67

78
@NgModule({
89
declarations: [
9-
AppComponent
10+
AppComponent,
11+
EmptyComponent
1012
],
1113
imports: [
1214
BrowserModule,

src/app/empty/empty.component.css

Whitespace-only changes.

src/app/empty/empty.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!--empty-->

src/app/empty/empty.component.spec.ts

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 { EmptyComponent } from './empty.component';
4+
5+
describe('EmptyComponent', () => {
6+
let component: EmptyComponent;
7+
let fixture: ComponentFixture<EmptyComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ EmptyComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(EmptyComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});

src/app/empty/empty.component.ts

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-empty',
5+
templateUrl: './empty.component.html',
6+
styleUrls: ['./empty.component.css']
7+
})
8+
export class EmptyComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit() {
13+
}
14+
15+
}

src/app/lazy/lazy.component.css

Whitespace-only changes.

src/app/lazy/lazy.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>
2+
lazy works!
3+
</p>

src/app/lazy/lazy.component.spec.ts

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 { LazyComponent } from './lazy.component';
4+
5+
describe('LazyComponent', () => {
6+
let component: LazyComponent;
7+
let fixture: ComponentFixture<LazyComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ LazyComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(LazyComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});

src/app/lazy/lazy.component.ts

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-lazy',
5+
templateUrl: './lazy.component.html',
6+
styleUrls: ['./lazy.component.css']
7+
})
8+
export class LazyComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit() {
13+
}
14+
15+
}

src/app/lazy/lazy.module.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { LazyComponent } from './lazy.component';
4+
import { RouterModule } from '@angular/router';
5+
6+
@NgModule({
7+
declarations: [LazyComponent],
8+
imports: [
9+
CommonModule,
10+
RouterModule.forChild([
11+
{path: '', component: LazyComponent},
12+
])
13+
],
14+
})
15+
export class LazyModule { }

0 commit comments

Comments
 (0)