4

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.

Bobby
  • 4,372
  • 8
  • 47
  • 103

2 Answers2

5

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 :)

Patoumpalou
  • 86
  • 1
  • 5
  • Although this works, its worth noting that it will not trigger any navigation events So if you're tracking urls, via NavigationEnd events, this will not be picked up. – Craig Wayne Feb 24 '22 at 08:35
-1

use Angular router

this.router.navigate(['/mypath']);
Constantin Guidon
  • 1,892
  • 16
  • 21