Skip to content

Commit

Permalink
(feature) router added
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenh77 committed Apr 3, 2017
1 parent e5bd63a commit 30a6a60
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h1>
{{title}}
</h1>
<main class="container">
<router-outlet></router-outlet>
</main>
20 changes: 16 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { Router } from '@angular/router';

import { AppComponent } from './app.component';
import { HomeComponent } from './home.component';
import { AwayComponent } from './away.component';
import { routing, appRoutingProviders } from './app.routes';

@NgModule({
declarations: [
AppComponent
AppComponent,
HomeComponent,
AwayComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
HttpModule,
routing
],
providers: [],
providers: [appRoutingProviders],
bootstrap: [AppComponent]
})
export class AppModule { }

export class AppModule {
constructor(router: Router) {
console.log('Routes: ', JSON.stringify(router.config));
}
}
13 changes: 13 additions & 0 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home.component';
import { AwayComponent } from './away.component';

const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'away', component: AwayComponent }
];

export const appRoutingProviders: any[] = [];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
8 changes: 8 additions & 0 deletions src/app/away.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
selector: 'away',
template: `<h1>Away</h1>`
})

export class AwayComponent {}
8 changes: 8 additions & 0 deletions src/app/home.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
selector: 'home',
template: `<h1>Home</h1>`
})

export class HomeComponent {}

0 comments on commit 30a6a60

Please sign in to comment.