change route using browser back button in angular 7 is not work

I Newer to angular how ensure the user when they click the browser back button and redirect to override the back button hist

import { HostListener } from '@angular/core';

@HostListener('window:popstate', ['$event'])
    onPopState(event:PopStateEventInit) {
      confirm("Are you sure want to discard");
      window.location.href='http://www.google.com'; 
    }