Backbone.js history 'on route change' event?

后端 未结 4 2195
遥遥无期
遥遥无期 2020-12-08 13:23

Is there a general event that fires every time we navigate to a different URL?

window.App =
  Models: {}
  Collections: {}
  Views: {}
  Routers: {}

  init:         


        
4条回答
  •  星月不相逢
    2020-12-08 14:28

    From the Backbone docs

    This method is called internally within the router, whenever a route matches and its corresponding callback is about to be executed. Override it to perform custom parsing or wrapping of your routes, for example, to parse query strings before handing them to your route callback, like so:

    var Router = Backbone.Router.extend({
      execute: function(callback, args) {
        args.push(parseQueryString(args.pop()));
        if (callback) callback.apply(this, args);
      }
    });
    

    This site has some useful code for redefining the Router to support 'before' and 'after' hooks, though it would require updating with each version-change of Backbone.

提交回复
热议问题