I have the following button in my code:
<button [routerLink]="['/answerslist', {id: applicant.id} ]" label="View Interview"></button>
Corresponding to the following route:
{ path: 'answerslist', component: AnswersListComponent },
I am expecting the URL to turn up as following: http://localhost:4200/answerslist?id=member2
However I am getting this when clicking on the button: http://localhost:4200/answerslist;id=member2
(Semicolon instead of question mark)
And as a result, the code doesn't work properly. I am retrieving the parameter for later use as follows:
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
}
});
}
So I need a way to construct the URL with a question mark, not a semicolon
CodePudding user response:
pls try this
< button [routerLink]="['answerslist']" [queryParams]="{ id: applicant.id }"></button >
more info can be found on https://angular.io/api/router/RouterLink