title: How to update matrix parameters in Angular2
body: <p>In Angular2, is there a way to update a matrix parameter, but navigate to the same component? Basically would like to transition easily from a url that looks like:</p>
  
  <p><code>/search;term=paris;pageSize=24;currentPage=1;someFilter=value;</code></p>
  
  <p>to the same thing, but with currentPage updated upon pagination:</p>
  
  <p><code>/search;term=paris;pageSize=24;currentPage=2;someFilter=value;</code></p>
  
  <p>using <code>router.navigate</code> hasn't appeared to be the best option, since I'd have to write plenty of my own logic to re-construct the url for <code>navigate</code>'s use (re-constructing something that already exists).</p>
  
  <p>For kicks and giggles, I did try</p>
  
  <p><code>this._router.navigate([this._router.url, {currentPage: this.pagination.currentPage}]);</code></p>
  
  <p>but (as you might expect), the router is dumb to the fact that there are matrix parameters on the current url, so the result is not pretty.</p>
  
  <p>EDIT: Should also mention that there may be any number of additional key/value pairs of matrix parameters, so hard-coding any route is out of the question</p>
  
  <p>EDIT: I've since tried to use <code>preserveQueryParams: true</code> like:</p>
  
  <p><code>this._router.navigate(["..", {currentPage: this.pagination.currentPage}], {preserveQueryParams: true});</code></p>
  
  <p>in order to get to an easily usable/transferable solution, but that did not keep the matrix params on the route.</p>
  
  <p>UPDATE: I've since implemented my own logic to get the required behavior, so here's a code snippet for the solution:</p>
  
  <pre><code>  let currentParamsArr: Params = this.route.snapshot.params;
    let currentParamsObj: any = { };
    for (let param in currentParamsArr) {
      currentParamsObj[param] = currentParamsArr[param];
    }
    currentParamsObj.currentPage = +pageNum; //typecasting shortcut
  
    this._router.navigate([currentParamsObj], { relativeTo: this.route });
  </code></pre>
  
  <p>This code loops through the parameters (as they stand in the snapshot), and creates an object out of them, then adds/edits the parameter that I desire to update, then navigates to the "new" route</p>
  
  <p>But, this is not pretty, as I'll essentially have this same logic in many places of the program or have to make a modification to Router or provide some other generic method.</p>