angular2路由器,如何将路由参数放入锚点?

时间:2016-04-13 12:52:22

标签: routing angular

<a [routerLink]="['/R1',{para:value}]">

创建

之类的链接
/link/route1/?para=value

我如何获得

/link/route1/para/value

出了一个标签?

1 个答案:

答案 0 :(得分:2)

在路线配置的路径中声明交配参数

@Component({
  selector: 'my-app',
  directives: [ROUTER_DIRECTIVES],
  template: `
  <h2>Hello</h2>
  <a [routerLink]="['/Form']">Form</a>
  <a [routerLink]="['/Other', {para:'xxx'}]">Other</a>
<router-outlet></router-outlet>  
`
})
@RouteConfig([
  {path: '/form', name: 'Form', component: HeroFormComponent, useAsDefault: true},
  {path: '/other/:para', name: 'Other', component: OtherComponent, }
])
export class App {
}

Plunker example