【发布时间】:2018-03-08 17:24:03
【问题描述】:
我目前正在尝试解决 Angular 4 中的路由问题。我希望 URL 包含参数数组,所以它看起来像这样:/#/WF001A;operationIds=146469,146470。这个 URL 是 Angular 使用 [routerLink] 生成的。参数需要可以从组件访问(我猜这应该不是问题)。
问题是 - 我不知道如何为其创建路线。我尝试了什么:
{path: 'WF001A/:operationIds', component: WF001AComponent}{path: 'WF001A/:operationIds[]', component: WF001AComponent}{path: 'WF001A:operationIds[]', component: WF001AComponent}{path: 'WF001A;:operationIds[]', component: WF001AComponent}
编辑: 这是链接的生成方式:
<a href="#" [routerLink]="['/WF001A', {operationIds:[146469, 146470]}]">test</a>
编辑 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);
});
}
}
【问题讨论】:
-
可以在模板中添加routerLink参数吗?
-
添加了我在模板中使用的 routerLink。
-
添加组件 sn-p.
-
你是如何解决
{path: 'WF001A:operationIds[]', component: WF001AComponent}这种语法的问题的?
标签: javascript angular typescript routing routes