Galdor
Galdor

Reputation: 1955

angular2 router, how to put a route parameter in an anchor?

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

creates links like

/link/route1/?para=value

how do I get

/link/route1/para/value

out of an a-tag?

Upvotes: 0

Views: 806

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657118

Declare a mating parameter in the path of the route config

@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

Upvotes: 2

Related Questions