You could use CanDeactivate
guard built into to angular. a use case in this blog here: https://medium.com/@altamashali/angular-candeactivate-guard-e9069e1adf0f
We have a NavigateAwayService in our app that utilises this. for when we want to show a popup saying "You have unsaved changes / are you sure?" when a user tries to navigate forward or back or close the browser tab.