Reese Davis
Reese Davis

Reputation: 147

how to stop url appending in angular 2 application using core angular2 router

My application is getting appened inside another application and I cannot append anything in the url as parent application is restrict.

Is there a way I can stop appending in the url. I am able to do the same in angular2 alpha 34 build by this.router.navigate(value, true);

I want to do the same in @angular:2.0.1 and in the html not in my typescript class by defining a method and calling it on (click).

Upvotes: 3

Views: 2476

Answers (2)

Aniruddha Das
Aniruddha Das

Reputation: 21688

skipLocationChange: true prevent angular2 to append anything in URL. As @Günter Zöchbauer suggested, You need to pass skipLocationChange: true as the default value is false.

full code will be:

import { Router }   from '@angular/router';

export class MovingInPages {

    constructor(private router: Router) {
    }

    moveToAnotherPage(value: string) {
        this.router.navigate([value], { skipLocationChange: true });
    }
}

The html will be like below:

<button type="button"  (click)="moveToAnotherPage('another-page-route')" class="btn btn-primary">Another page</button>

Upvotes: 2

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657108

Sounds like you are looking for skipLocationChange:

router.navigate(['team', 33, 'user', 11], {relativeTo: route, skipLocationChange: true });

See also https://angular.io/docs/ts/latest/api/router/index/Router-class.html

Upvotes: 2

Related Questions