There have already been written lots of stuff about unsubscribing from observables in standard Angular workflow, but not so much about unsubscribing on page refresh (at least I haven't found much).
So, what can be done with subscriptions which should be unsubscribed in ngOnDestroy
(which is never called on page refresh)? The only material I came across during investigation was this, it uses javascript onbeforeunload
function.
ngOnInit(){
//Some stuff
window.onbeforeunload = () => this.ngOnDestroy();
}
ngOnDestroy(){
//Some stuff
}
This is quite an old answer, so maybe some things have moved further - is there currently any 'more Angular' way how to handle such subscriptions on page refresh?