javascript - Cancel route using Sammy.js without affecting history -


i want intercept route changes sammy first check if there pending action. have done using sammy.before api , return false cancel route. keeps user on 'page' still changes hash in browsers address bar , adds route browsers' history. if cancel route, dont want in address bar nor history, instead expect address stay same.

currently, around can either call window.history.back (yuk) go original spot in history or sammy.redirect. both of less ideal.

is there way make sammy cancel route stays on current route/page, leaves address bar is, , not add history?

if not, there routing library this?

sammy.before(/.*/, function () {     // can cancel route if returns false     var response = routemediator.canleave();  if (!isredirecting && !response.val) {     isredirecting = true;     // keep hash url same in address bar     window.history.back();     //this.redirect('#/specificpreviouspage');  } else {     isredirecting = false; } return response.val; }); 

in case else hits this, here ended up. decided use context.setlocation feature of sammy handle resetting route.

sammy.before(/.*/, function () {     // can cancel route if returns false     var         context = this,         response = routemediator.canleave();      if (!isredirecting && !response.val) {         isredirecting = true;         toastr.warning(response.message); // toastr displays message         // keep hash url same in address bar         context.app.setlocation(currenthash);     }     else {         isredirecting = false;         currenthash = context.app.getlocation();     }     return response.val; }); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -