标签:
1. In index.html:
<base href="/">
2. Include router file:
import ‘angular2/router‘;
3. Inject the provider:
bootstrap(App, [
ROUTER_PROVIDERS
]);
4. @RouterConfig:
@RouteConfig([ {path: ‘/home‘, name: ‘Home‘, component: HomeComponent, useAsDefault: true}, {path: ‘/about‘, name: ‘About‘, component: AboutComponent} ])
5. Inject ROUTER_DIRECTIVES:
directives: [HomeComponent, AboutComponent, ROUTER_DIRECTIVES],
6. Define the link:
<a href="" [routerLink]="[‘Home‘]">Home</a> <a href="" [routerLink]="[‘Home‘, {username: ‘Hero‘}]">Owner</a> <a href="" [routerLink]="[‘About‘]">About</a>
7. Define the router-outlet:
<nav>
<a href="" [routerLink]="[‘Home‘]">Home</a>
<a href="" [routerLink]="[‘Home‘, {username: ‘Zhentian Wan‘}]">Owner</a>
<a href="" [routerLink]="[‘About‘]">About</a>
</nav>
<router-outlet></router-outlet>
8. If deal with RouterParams:
constructor(private _routeParams: RouteParams){ this.username = _routeParams.get(‘username‘); }
----------------
[Angular 2] Router basic and Router Params
标签:
原文地址:http://www.cnblogs.com/Answer1215/p/5403042.html