0

Is there some how using a code to add a new URL parameter, for example:

http://example.com/mypage?par=1&par2=2

I need in my code something like:

if (myVar == 'abc') { 
    // add a par3=3 without navigate/refresh the page - just to 
    // add a decoration on the URL for bookmarks purposes, 
    // for example: when user bookmark it and go back, 
    //I will be displaying the same dialog box 
}
danday74
  • 52,471
  • 49
  • 232
  • 283
Marco Jr
  • 6,496
  • 11
  • 47
  • 86
  • 1
    Possible duplicate of [Change route params without reloading in angular 2](http://stackoverflow.com/questions/35618463/change-route-params-without-reloading-in-angular-2) – Pankaj Parkar Mar 18 '16 at 12:09

2 Answers2

1

You could use Angulars Location. In this way only the url gets updated, but the router is not navigating to it.

import {Location} from 'angular2/router';
 class Component {
  constructor(location: Location) {
    location.go('/foo');//Add your params here
  }
}
Daskus
  • 929
  • 1
  • 10
  • 25
0

If you implement CanReuse and return true you can renavigate to the URL with the added parameter, without everything being reloaded.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567