title: Angular How to detect browser back button press before route changing
body: <p>I'm using Angular 12 SPA app.
  When user press the browser back button. I want to show the warning message before leave in current route url.
  Current page &quot;localhost/note&quot;</p>
  <p>If user click back button. url changed &quot;localhost/home&quot; then show the warning message(page is not changed, only url changed)</p>
  <p>However, I want to show the message BEFORE route change.
  I'm using HostListener. It shows alert after url/route change</p>
  <pre><code>@HostListener('window:popstate', ['$event'])
    onPopState(event: any) {
      alert(&quot;Do you really want to move other page?&quot;);
    }
  </code></pre>