How can I ask users to confirm before leaving the page on the Aurelia.js

怎甘沉沦 提交于 2020-01-14 09:56:47

问题


I have an long operation on the page. How can I said user wait a bit when he make the navigation change?

The idea is to show the promt dialog. But the trouble prevent default Aurelia router behavior.

How make it works in Aurelia.js?


回答1:


You could use the canDeactivate hook of your view-model. Like this:

canDeactivate() {
   return confirm('Are you sure you want to leave this page?');
}

canDeactivate() - Implement this hook if you want to control whether or not the router can navigate away from your view-model when moving to a new route. Return a boolean value, a promise for a boolean value, or a navigation command.

More information at http://aurelia.io/docs.html#/aurelia/framework/1.0.0-beta.1.2.2/doc/article/cheat-sheet/7



来源:https://stackoverflow.com/questions/37183838/how-can-i-ask-users-to-confirm-before-leaving-the-page-on-the-aurelia-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!