Assuming I have the following url:
team/11/user/22
how do I traverse to team ID but keeping user ID intact?
team/22/user/22
this.router.createUrlTree(['../../team/22'], {relativeTo: this.route}) deletes the user parameters.
Hope this helps someone, try something like this:
// import location
import {
Location
} from '@angular/common';
updateUrl() {
// or pass teamId&userId into func
const queryParams = {
teamId: this.teamId,
userId: this.userId
};
const urlTree = this.router.createUrlTree([], {
queryParams: queryParams,
relativeTo: this.activeRoute,
skipLocationChange: true
});
this.location.replaceState(urlTree.toString());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With