我的代码中有以下按钮:
<button [routerLink]="['/answerslist', {id: applicant.id} ]" label="View Interview"></button>
对应如下路线:
{ path: 'answerslist', component: AnswersListComponent },
我希望 URL 如下所示: http://localhost:4200/answerslist?id=member2
但是我在点击按钮时得到了这个:http://localhost:4200/answerslist;id=member2
(分号代替问号)
结果,代码无法正常工作。我正在检索参数以供以后使用,如下所示:
getUser(){
this.activeRoute.queryParams.subscribe(
(params) => {
const id = params['id'];
if (id) {
this.currentUser = id;
}
else{
console.log('id not passed'); //this is what currenlty gets printed
}
});
}
所以我需要一种用问号而不是分号来构造 URL 的方法