1
votes

Based on a single ItemView, I would like a way to implement 'are you sure you want to navigate away from this page? I have tried using 'onBeforeClose' events, but I don't think these can cancel the eventual navigation to another route. I think an earlier release of Marionette had this functionality, but I'm on 1.8.4.

Having 'onRoute' on each AppRouter also seems to lack the ability to cancel routing given some condition based on the current view. My next idea was overriding the 'navigate' function to check for some condition.

Having a 'before' function define seems to cancel routing when returning false, but at that point the url hash has already changed.

Any Marionette/Backbone specific pointers?

1
It can't be done with marionette. I recently answered the similar question, check it outknpsck

1 Answers

2
votes

In a current marionette app I have a global click handler which handles click events on all links (href like #settings/user) and then manually calls Backbone.history.navigate(route, {trigger: true|false});. When this handler is called I am checking a global defined variable like App.isScreenLocked, and if that is true I do not call navigate.