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

Commit df5d27d

Browse files
Example of Angular 2 lazy loading to help with #465
1 parent 1f03b1e commit df5d27d

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

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

Lines changed: 1 addition & 3 deletions
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
])
Lines changed: 14 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"angular2-universal": "^2.1.0-rc.1",
2121
"angular2-universal-patch": "^0.2.1",
2222
"angular2-universal-polyfills": "^2.1.0-rc.1",
23+
"angular2-router-loader": "^0.3.4",
2324
"aspnet-prerendering": "^2.0.0",
2425
"aspnet-webpack": "^1.0.17",
2526
"awesome-typescript-loader": "^3.0.0",

templates/Angular2Spa/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = (env) => {
1616
},
1717
module: {
1818
rules: [
19-
{ test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] },
19+
{ test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] },
2020
{ test: /\.html$/, use: 'html-loader?minimize=false' },
2121
{ test: /\.css$/, use: ['to-string-loader', 'css-loader'] },
2222
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }

0 commit comments

Comments
 (0)