title: Angular 6 - logout user when only browser close not on refresh
body: <p>logout the user when he close the browser not on refresh</p>
  
  <p><code>@HostListener('window:beforeunload', [ '$event' ])
  unloadHandler(event) {
  this.logout()
  }</code></p>
  
  <p><code>logout() {
      localStorage.removeItem('id');
      this.router.navigate(["/login"]);
    }</code></p>
  
  <p>I use this, it works but the user also logout on refresh the browser</p>