Skip to content

Commit 85bd5c6

Browse files
committed
add router and routes
1 parent 5d8ee93 commit 85bd5c6

10 files changed

+83
-2
lines changed

src/app/app.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<h1>
22
{{title}}
33
</h1>
4+
<router-outlet></router-outlet>

src/app/app.module.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,39 @@ import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
33
import { FormsModule } from '@angular/forms';
44
import { HttpModule } from '@angular/http';
5+
import { RouterModule, Route } from '@angular/router';
56

67
import { AppComponent } from './app.component';
8+
import { ItemsComponent } from './items/items.component';
9+
import { HomeComponent } from './home/home.component';
10+
11+
const homeRoute: Route = {
12+
path: '',
13+
component: HomeComponent
14+
};
15+
16+
const otherRoute: Route = {
17+
path: 'other',
18+
component: ItemsComponent
19+
};
720

821
@NgModule({
922
declarations: [
10-
AppComponent
23+
AppComponent,
24+
ItemsComponent,
25+
HomeComponent
1126
],
1227
imports: [
1328
BrowserModule,
1429
FormsModule,
15-
HttpModule
30+
HttpModule,
31+
RouterModule.forRoot([
32+
{
33+
path: 'items',
34+
component: ItemsComponent
35+
},
36+
homeRoute,
37+
otherRoute])
1638
],
1739
providers: [],
1840
bootstrap: [AppComponent]

src/app/home/home.component.css

Whitespace-only changes.

src/app/home/home.component.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>
2+
home works!
3+
</p>

src/app/home/home.component.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* tslint:disable:no-unused-variable */
2+
3+
import { TestBed, async } from '@angular/core/testing';
4+
import { HomeComponent } from './home.component';
5+
6+
describe('Component: Home', () => {
7+
it('should create an instance', () => {
8+
let component = new HomeComponent();
9+
expect(component).toBeTruthy();
10+
});
11+
});

src/app/home/home.component.ts

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

src/app/items/items.component.css

Whitespace-only changes.

src/app/items/items.component.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>
2+
items works!
3+
</p>

src/app/items/items.component.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* tslint:disable:no-unused-variable */
2+
3+
import { TestBed, async } from '@angular/core/testing';
4+
import { ItemsComponent } from './items.component';
5+
6+
describe('Component: Items', () => {
7+
it('should create an instance', () => {
8+
let component = new ItemsComponent();
9+
expect(component).toBeTruthy();
10+
});
11+
});

src/app/items/items.component.ts

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

0 commit comments

Comments
 (0)