9

In my Angular 2 web application I would like to change the url page in the browser. For example I'd like to change it from:

http://localhost:63000/my-page

to

http://localhost:63000/your-page

It must not redirect, no page load, and browser history must reflect the page change.

Can this be done?

1 Answer 1

12

This can be achieved by below function available in angular 4

location.replaceState(path: string, query?: string): void;

Before doing this you need to get location object by injecting in your component or directive constructor.

  constructor(private location: Location)

And importing Location class like this -

import { Location } from '@angular/common';
Sign up to request clarification or add additional context in comments.

Comments

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.