[Angular2 Router] Build Angular 2 Navigation with routerLink

Angular 2 navigation is configured using the routerLink directive. The routerLink directive behaves like an href’s you are familiar with, but it hooks into Angular 2’s router to navigate between your defined routes.

 

app.component.html:

<nav>
  <a routerLink="">Home</a>
  <a routerLink="contact">Contact</a>
</nav>
<router-outlet></router-outlet>

 

app.routers.ts:

import {HomeComponent} from "./home/home.component";
import {RouterModule} from "@angular/router";
import {ContactComponent} from "./contact/contact.component";
const routes = [
  {path: '', component: HomeComponent},
  {path: 'contact', component: ContactComponent},
];

export default RouterModule.forRoot(routes);

 

Github

posted @ 2016-09-25 02:54  Zhentiw  阅读(381)  评论(0编辑  收藏  举报