title: Can not prevent browser page refresh/reload in angular application
body: <p>I have my site with angularjs SPA. When user clicks on refresh button or press F5/ Ctrl + F5 to I want to prevent, or abort page reloading. Unfortunately, solution with <code>onbeforeunload</code> and <code>onunload</code> events are not working. Actually, they are called, <code>event.preventDefault()</code> line is reached, there are any messages in console, but browser continue to load page.</p>
  
  <p>My current module <code>.run()</code> code:</p>
  
  <pre><code>let window = angular.element($window);
  window.on("beforeunload", (event) =&gt; {
      event.preventDefault();
  }).on("unload", (event) =&gt; {
      event.preventDefault();
  });
  
  // This is just for sure that I have my handlers registered 
  $window.onbeforeunload = (event) =&gt; {
      event.preventDefault();
  }
  
  $window.onunload = (event) =&gt; {
      event.preventDefault();
  }
  </code></pre>
  
  <p>How can I really handle this in angular?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I need this for reloading actual state instead of page. So when user clicks refresh I want to just reload current state with <code>$stateProvider</code> and not to reload the whole page</p>