Angular 4 - How to route to a particular component when back button is pressed?

Viewed 4925

I want to route to a particular path when the back button will be clicked in the browser.

I was trying the following code snippet. But it changes the URL to the desired one for just a moment, and then routing to the previous actual URL.

constructor(location: PlatformLocation, private router: Router) {
    location.onPopState(() => {
        router.navigate(['/home']);
    });
}
3 Answers
Related