How do I track router change events in Backbone.js
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to run a function every time the application switches URLs in Backbone.js, and I need to know the hashtag the URL has changed to. I'm assuming there is an event that I can bind to but I haven't been able to figure out which event and what object to bind to. Specifically I want to ship the new URL to an analytics application. 回答1: I know this is an old post, but like @kirk suggested, Backbone.js already has it built it. Backbone.history.on("all", function (route, router) { //console.log(window.location.hash); }); I think you'd be