Permalink
Browse files

(feature) router added

  • Loading branch information...
stevenh77 committed Apr 3, 2017
1 parent e5bd63a commit 30a6a60c0f5b195d5edb290e8f3df902ec605ccf
Showing with 48 additions and 7 deletions.
  1. +3 −3 src/app/app.component.html
  2. +16 −4 src/app/app.module.ts
  3. +13 −0 src/app/app.routes.ts
  4. +8 −0 src/app/away.component.ts
  5. +8 −0 src/app/home.component.ts
@@ -1,3 +1,3 @@
-<h1>
- {{title}}
-</h1>
+<main class="container">
+ <router-outlet></router-outlet>
+</main>
View
@@ -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));
+ }
+}
View
@@ -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);
@@ -0,0 +1,8 @@
+import { Component } from '@angular/core';
+
+@Component({
+ selector: 'away',
+ template: `<h1>Away</h1>`
+})
+
+export class AwayComponent {}
@@ -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.