Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 492
Egor Malkevich Avatar asked May 12 '16 10:05

Egor Malkevich


1 Answers

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

like image 89
Fabio Luz Avatar answered Nov 02 '22 17:11

Fabio Luz