Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 7ded0a0

Browse files
committedDec 1, 2016
Example of Angular 2 lazy loading to help with #465
1 parent 2b2465a commit 7ded0a0

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed
 

‎templates/Angular2Spa/ClientApp/app/app.module.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import { AppComponent } from './components/app/app.component'
55
import { NavMenuComponent } from './components/navmenu/navmenu.component';
66
import { HomeComponent } from './components/home/home.component';
77
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
8-
import { CounterComponent } from './components/counter/counter.component';
98

109
@NgModule({
1110
bootstrap: [ AppComponent ],
1211
declarations: [
1312
AppComponent,
1413
NavMenuComponent,
15-
CounterComponent,
1614
FetchDataComponent,
1715
HomeComponent
1816
],
@@ -21,7 +19,7 @@ import { CounterComponent } from './components/counter/counter.component';
2119
RouterModule.forRoot([
2220
{ path: '', redirectTo: 'home', pathMatch: 'full' },
2321
{ path: 'home', component: HomeComponent },
24-
{ path: 'counter', component: CounterComponent },
22+
{ path: 'counter', loadChildren: './components/counter/counter.module#CounterModule' },
2523
{ path: 'fetch-data', component: FetchDataComponent },
2624
{ path: '**', redirectTo: 'home' }
2725
])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NgModule } from '@angular/core';
2+
import { RouterModule } from '@angular/router';
3+
import { CounterComponent } from './counter.component';
4+
5+
@NgModule({
6+
imports: [
7+
RouterModule.forChild([
8+
{ path: '', component: CounterComponent }
9+
])
10+
],
11+
exports: [ RouterModule ],
12+
declarations: [ CounterComponent ]
13+
})
14+
export class CounterModule {}

‎templates/Angular2Spa/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@angular/router": "3.0.2",
1717
"@types/node": "^6.0.42",
1818
"angular2-platform-node": "~2.0.11",
19+
"angular2-router-loader": "^0.3.4",
1920
"angular2-template-loader": "^0.6.0",
2021
"angular2-universal": "~2.0.11",
2122
"angular2-universal-polyfills": "~2.0.11",

‎templates/Angular2Spa/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var sharedConfig = {
1313
},
1414
module: {
1515
loaders: [
16-
{ test: /\.ts$/, include: /ClientApp/, loaders: ['ts-loader?silent=true', 'angular2-template-loader'] },
16+
{ test: /\.ts$/, include: /ClientApp/, loaders: ['ts-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] },
1717
{ test: /\.html$/, loader: 'html-loader?minimize=false' },
1818
{ test: /\.css$/, loader: 'to-string-loader!css-loader' },
1919
{ test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } }

0 commit comments

Comments
 (0)