Javascript 角度为4的阵列参数布线

Javascript 角度为4的阵列参数布线,javascript,angular,typescript,routing,routes,Javascript,Angular,Typescript,Routing,Routes,我目前正在尝试解决Angular 4中的布线问题。我希望URL包含参数数组,因此看起来像这样:/#/WF001A;操作ID=146469146470。此URL由Angular使用[routerLink]生成。参数需要可以从组件访问(我想这应该不是问题) 问题是-我不知道如何为它创建路线。我尝试的是: {path:'WF001A/:operationIds',component:WF001AComponent} {path:'WF001A/:operationIds[],component:WF

我目前正在尝试解决Angular 4中的布线问题。我希望URL包含参数数组,因此看起来像这样:
/#/WF001A;操作ID=146469146470
。此URL由Angular使用[routerLink]生成。参数需要可以从组件访问(我想这应该不是问题)

问题是-我不知道如何为它创建路线。我尝试的是:

  • {path:'WF001A/:operationIds',component:WF001AComponent}
  • {path:'WF001A/:operationIds[],component:WF001AComponent}
  • {path:'WF001A:operationIds[],component:WF001AComponent}
  • {path:'WF001A;:operationIds[],component:WF001AComponent}
编辑: 以下是链接的生成方式:

编辑2: 组件类别:

export class WF001AComponent implements OnInit {
    public title = 'WF001A';

    public constructor (private WF001AService: WF001AService, private route: ActivatedRoute) {}

    public ngOnInit(): void {
        this.route.paramMap.subscribe(params => {
            // This is never executed, for route is not recognized
            let myArray=params.getAll('operationIds');
            console.log(myArray);
        });
    }
}

我假设组件中有ActivatedRoute对象,类似于:

constructor(
    ...,
    private route: ActivatedRoute) { }
this.route.paramMap.subscribe(params => {
  let i=0;
  let myArray=params.getAll('operationIds');
}
我假设WF001A是参数名,因此您可以执行以下操作:

constructor(
    ...,
    private route: ActivatedRoute) { }
this.route.paramMap.subscribe(params => {
  let i=0;
  let myArray=params.getAll('operationIds');
}

您可以在

中找到有关可选参数的更多信息。我假设您的组件中有ActivatedRoute对象,例如:

constructor(
    ...,
    private route: ActivatedRoute) { }
this.route.paramMap.subscribe(params => {
  let i=0;
  let myArray=params.getAll('operationIds');
}
我假设WF001A是参数名,因此您可以执行以下操作:

constructor(
    ...,
    private route: ActivatedRoute) { }
this.route.paramMap.subscribe(params => {
  let i=0;
  let myArray=params.getAll('operationIds');
}

您可以在

中找到有关可选参数的更多信息。您可以在模板中添加routerLink参数吗?添加了我在模板中使用的routerLink。添加了组件片段。您是如何解决
{path:'WF001A:operationId[],component:WF001AComponent}的问题的
这种语法?你能在模板中添加routerLink参数吗?添加了我在模板中使用的routerLink。添加了组件片段。你是如何解决
{path:'WF001A:operationIds[],component:WF001AComponent}
这种语法的问题的?我认为这并不能解决问题。我在控制台中遇到此错误:
error:无法匹配任何路由。URL段:'WF001A;operationIds=146469146470'
,这意味着没有为数组准备路由。我尝试使用您的示例,但不幸的是它从未执行过,因为Angular实际上不知道任何与
WF001A匹配的路由;操作ID=146469146470
WF001A/操作ID=146469146470
。但是,您对处理部分的看法是正确的,在发送了如下参数:
WF001A/146469146470
之后,我已经能够获得这些数据。不确定如何解决这个问题,因为这部分是序列化这些参数的方法的错误,但我认为你的答案应该被接受,因为它踢出了我正确的方向:)我认为这并不能解决问题。我在控制台中遇到此错误:
error:无法匹配任何路由。URL段:'WF001A;operationIds=146469146470'
,这意味着没有为数组准备路由。我尝试使用您的示例,但不幸的是它从未执行过,因为Angular实际上不知道任何与
WF001A匹配的路由;操作ID=146469146470
WF001A/操作ID=146469146470
。但是,您对处理部分的看法是正确的,在发送了如下参数:
WF001A/146469146470
之后,我已经能够获得这些数据。不确定如何解决这个问题,因为这部分是序列化这些参数的方法的错误,但我认为你的答案应该被接受,因为它踢向了我正确的方向:)