Block routing if form is dirty [ Angular 2 ]

2019-07-18 08:48发布

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?

2条回答
Animai°情兽
2楼-- · 2019-07-18 08:52

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-07-18 08:57

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.

查看更多
登录 后发表回答