Backbone router events
-
30-10-2019 - |
Question
Does in Backbone.Router
exists the events both before and after performing routing?
My app works with jQuery.mobile
and call to $.mobile.changePage was needed before route was performed and in controller have access to currently showing page by $.activePage. When action of controller is done, I should trigger the create
event on document to get 'enhanced' by $.mobile newly created elements.
I did this by replacing loadUrl
Backbone.history.loadUrl = ( function( old ){
return function() {
Router.trigger("all:before");
old.apply( Backbone.history, arguments );
Router.trigger("all:after" );
}
})( Backbone.history.loadUrl );
//Router.initialize
initialize: function() {
this.bind( "all:before", function( ) {
$.mobile.changePage( window.location.hash.split( "/" )[0] || "home", { changeHash:false} );
});
this.bind( "all:after", function() {
$.mobile.activePage.trigger('create');
});
}
Is there maybe some built-in events like this?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow