解决方法
_.wrap不是一个解决方案,如果你有20个路由,你必须把它们全部包装.
但是你可以用元编程来做到这一点
class Backbone.FlexRouter extends Backbone.Router route: (route,name,handler) -> super route,-> @trigger "route:before" handler() @trigger "route:after"
UPD:我相信JS应该是这样的(但我没有测试它)
var rp = Backbone.Router.prototype rp.routeWithoutEvents = rp.route rp.route = function(route,handler){ var that = this this.routeWithoutEvents(route,function(){ that.trigger("route:before") handler() that.trigger("route:after") }) }