HTTP and Routing - Basic Routing
import { Component, Inject, OnInit } from '@angular/core';
import { Path1Component } from './path1/path1.component'
import { Path2Component } from './path2/path2.component'
import { ROUTER_DIRECTIVES, Routes, Router } from '@angular/router';
@Component({
moduleId: module.id,
selector: 't3-app',
templateUrl: 't3.component.html',
styleUrls: ['t3.component.css'],
directives: [ROUTER_DIRECTIVES]
})
@Routes([
{path:'/path1', component: Path1Component},
{path:'/path2', component: Path2Component}
])
export class T3AppComponent implements OnInit{
ngOnInit(){
//this.router.navigate(['/path1']);
}
}
<nav>
<a [routerLink]="['/path1']">Page 1</a>
<a [routerLink]="['/path2']">Page 2</a>
</nav>
<router-outlet></router-outlet>
import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode, provide } from '@angular/core';
import { T3AppComponent, environment } from './app/';
import { ROUTER_PROVIDERS } from '@angular/router';
if (environment.production) {
enableProdMode();
}
bootstrap(T3AppComponent,[
ROUTER_PROVIDERS
]);