Marco Jr
Marco Jr

Reputation: 6806

Angular 2 - add URL parameter on demand

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 
}

Upvotes: 0

Views: 763

Answers (2)

Daskus
Daskus

Reputation: 969

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
  }
}

Upvotes: 1

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657851

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

Upvotes: 0

Related Questions