knockout.js - Intercept route navigation and ask user "are you sure you wish to leave this page?" -


i have durandal app allows user update various bits of profile information. bits of data, user must click "save" indicate want save changes.

in event user attempts navigate away current view unsaved changes, want intercept navigation , popup modal saying "you have unsaved changes--do want save them before leaving view?"

however, in reviewing durandal router plugin documentation, haven't been able determine how intercept navigation requests in viewmodel. think want listen the router:route:activating event. but:

  1. i'm not sure , how setup listener this.
  2. i don't know how cancel navigation (so can instead pop modal) in event handler.

you can in candeactivate event durandal has.

var candeactivate = function () { // check if data has unsaved changes logic in haschanges() method if (haschanges()) {             var msg = 'do want leave , cancel?';             return app.showmessage('message', 'confirm title', ['yes', 'no'])                 .then(function (selectedoption) {                     if (selectedoption === 'yes') {                        // cancel changes here                     }                     return selectedoption;                 });         }         return true; }; 

this cancel navigation based on user's selected option.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -