我目前正在嘗試解決Angular 4中的路由問題。我希望URL包含參數數組,因此它看起來像這樣:/#/WF001A;operationIds=146469,146470
。此URL由Angular使用[routerLink]生成。參數需要從組件中訪問(這應該不是一個問題,我猜)。在Angular 4中使用數組參數的路由
問題是 - 我不知道如何爲它創建路線。我的嘗試:
{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。 – lemon
添加組件片段。 – lemon