Crocsx
Crocsx

Reputation: 7609

Change url without redirect in angular 7

I would like to add a path to the url, without redirecting the page.

like I am on page /home/ I want to move to /home/item1 without triggering a redirection.

I found many example on stack, but none of them work in angular 7.

location.go or location.replaceState are not available from

constructor(private location: Location) { }

I am trying to find a way in angular 7.

Upvotes: 5

Views: 7344

Answers (2)

Patoumpalou
Patoumpalou

Reputation: 106

Other solutions here : Angular2: unable to navigate to url using location.go(url)

Using:

import {Location} from '@angular/common'; 

constructor(private location: Location){}

location.go('myurl');

works for me :)

Upvotes: 6

Constantin Guidon
Constantin Guidon

Reputation: 1892

use Angular router

this.router.navigate(['/mypath']);

Upvotes: -1

Related Questions