问题
I am blocked with this,
In Angular 2, I need to block any user click event, even browser refresh if the form in the page is dirty
Could you help me with ideas?
回答1:
It seems you are looking for canDeactivate
It allows you to block routing away. You would need a shared service where you update the forms dirty state so that the guard can access it.
回答2:
The angular docs cover this exact question:
https://angular.io/guide/router#candeactivate-handling-unsaved-changes
I'd leave that as a comment but I lack the reputation to do so.
来源:https://stackoverflow.com/questions/39091338/block-routing-if-form-is-dirty-angular-2