You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Backbone-beforepopstate overrides the native Backbone.history.start with its own version. Now the new version calls the original, so everything continues to work as normal, except for one thing: the new version doesn't return the value the original version would.
Normally Backbone.history.start returns either true or false, depending on whether it matched a route or not (ie. whether it got a pseudo-404). However, beforepopstate does the following:
BB.history._originalStart(options);
without storing or returning the return value.
One simple solution would be to save the return value, and then return it after the on('popstate' section:
var matchFound = BB.history._originalStart(options);
// This prevents the popstate event handler from calling any handlers after
// the one that backbone uses to fire navigation
jQuery(window).on('popstate', function(e) {
if (history._popCancelled) {
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
history._popCancelled = false;
}
});
return matchFound;
However, if the hookup of the popstate event handler could happen before start is called, then all that cold be simplified to:
Backbone-beforepopstate overrides the native Backbone.history.start with its own version. Now the new version calls the original, so everything continues to work as normal, except for one thing: the new version doesn't return the value the original version would.
Normally Backbone.history.start returns either true or false, depending on whether it matched a route or not (ie. whether it got a pseudo-404). However, beforepopstate does the following:
without storing or returning the return value.
One simple solution would be to save the return value, and then return it after the
on('popstate'
section:However, if the hookup of the popstate event handler could happen before start is called, then all that cold be simplified to:
Either way, please preserve the return value of start, as it's an important part of Backbone routing.
The text was updated successfully, but these errors were encountered: