RouterLink数组

Dar*_*g8r 6 routerlink angular

我有一个超链接,我需要在Angular 4中建立一个路由器链接.我有很多部分到url,其中一部分是一个数组.我不确定如何将数组拆分为routerlink数组的部分.

拿这个人为的例子:

[routerLink]="['/customers', customerid, orderid, arrayofints, anotherint]"
Run Code Online (Sandbox Code Playgroud)

我希望路由器看起来像customerid = 10,order = 500,arrayofints = [1,2,3],anotherint = 888

"/customers/10/500/1/2/3/888"
Run Code Online (Sandbox Code Playgroud)

我最终得到了类似的东西:

"/customers/10/500;0=1;1=2;2=3/888"
Run Code Online (Sandbox Code Playgroud)

jon*_*rpe 7

对于任何非平凡的事情,我都会在组件代码而不是模板中完成工作.所以在模板中:

[routerLink]="customerRouteFor(anotherint)"
Run Code Online (Sandbox Code Playgroud)

在组件中,您可以使用以下...spread语法:

customerRouteFor(anotherint: number): (string | number)[] {
  return ['/customers', this.customerid, this.orderid, ...this.arrayofints, anotherint];
}
Run Code Online (Sandbox Code Playgroud)

concat在我看来,这似乎比方法更清洁.