Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Router Navigate Using CreateUrlTree

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.

like image 311
Vignesh Rangaraj Avatar asked Dec 14 '25 20:12

Vignesh Rangaraj


1 Answers

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());
}
like image 113
alphapilgrim Avatar answered Dec 16 '25 22:12

alphapilgrim