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?
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With