For those still looking for another way to handle this in Angular. You can try to do this:
<router-outlet (window:beforeunload)="doBeforeUnload()" (window:unload)="doUnload()"></router-outlet>
router-outlet, , app.component.html, . , beforeunload false, unload . , , , . :
doBeforeUnload() {
    // Alert the user window is closing 
    return false;
}
doUnload() {
    // Clear session or do something
    this.auth.getLogout();
}
PD: Angular 6.