I’m looking to have a CanDeactivate guard only fire on Back button navigation and not upon clicking a link. I have an unrouted section of my application that I’d like to enable back button navigation for, so I’d like to deactivate the back button and then change the view instead.
I’ve tried filtering on event.type === ‘popstate’, then using history.pushState and location.go but those don’t seem to work – navigation away still occurs.
I was considering having a service that captures router events and holds the past event type in a BehaviorSubject. Wondering if there will be concurrency issues with that when accessed from the guard.
Frederick Kozlowski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.