5

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.

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
-1

use Angular router

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

1 Comment

He asked that it should not redirect. But I think the solution you gave will redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.