Backbone router 未生效可能狀況

define(['backbone'],function(Backbone){
 	var navController = Backbone.Router.extend({
 		routes : {
 			'test':'test',
 			'nav/:path': 'gotoNav'
		},
		initialize:function(){//constructor
			console.log(123);
		},
		test:function(){alert(1)},
		gotoNav:function(path){
			console.log(path);
		}
 	});
 	return navController;
})

今天寫一個backbone router, 結果發現routes沒有生效, 因爲長時間沒用了   html

開始時候發現 函數

狀況1: spa

Backbone.history.start() 忘記調用了 code

狀況2: router

手賤,心血來潮把初始化方法寫成 constructor 結果不生效,修改 initialize 後正常工做 htm

constructor / initialize new Router([options]) 
When creating a new router, you may pass its routes hash directly as an option, if you choose. All options will also be passed to your initialize function, if defined.

我XX 我還覺得這2個方法是一樣效果的呢, 如今看來  initialize 應該是backbone constructor 的回調函數(猜想啊) 閒情能夠看backbone源碼 backbone

記錄一下吧,省的之後又忘記了 回調函數

相關文章
相關標籤/搜索