これは私のCoffescriptルータークラスです:
class App.Router extends Backbone.Router
initialize: ->
console.log 'Router.init'
@on 'all', ->
console.info 'route changed'
routes:
'': 'home'
'test': 'test'
home: ->
console.log 'home routed'
test: ->
console.log 'test routed'
ローカルホストページをリロードすると、「@ on'all'」コールバックが2回トリガーされるようです(firebugのdouble console.info ...)。
これは私のfirebugの出力です:
App.init
Session.init
Router.init
home routed
route changed
route changed
ご覧のとおり、「ルート変更」出力はホームルートの後に配置されます...
そして最後に、これは私のブートストラップコードです(私のアプリの名前空間を使用しています...)、ここにhistory.startを配置しました
App =
init: ->
console.log 'App.init'
@session = new App.Model.Session
@router = new App.Router
# @userPanel = new App.View.UserPanel
Backbone.history.start pushState: true
Model: {}
View: {}