2
工作app.js木偶AppRouter不Browserify
module.exports = function() {
if (!window.__medicineManager) {
var Backbone = require('backbone');
var Marionette = require('backbone.marionette');
var MedicineManager = new Marionette.Application();
MedicineManager.addRegions({
mainRegion: "#main-region"
});
MedicineManager.navigate = function (route, options) {
options || (options = {});
Backbone.history.navigate(route, options);
};
MedicineManager.getCurrentRoute = function() {
return Backbone.history.fragment;
};
MedicineManager.on("start", function() {
if (Backbone.history) {
Backbone.history.start();
}
});
MedicineManager.start();
window.__medicineManager = MedicineManager;
}
return window.__medicineManager;
}();
medicine_app.js
var MedicineManager = require('app');
var Backbone = require('backbone');
var Marionette = require('backbone.marionette');
MedicineManager.module("MedicineApp", function (MedicineApp) {
MedicineApp.Router = Marionette.AppRouter.extend({
appRoutes: {
"": "showSearchOption",
"show/*id": "showMedicine"
}
});
var API = {
showSearchOption: function() {
console.log('show search option');
},
showMedicine: function (id) {
console.log('show ' + id);
}
};
MedicineManager.addInitializer(function() {
console.log('MedicineApp.Router initialised');
new MedicineApp.Router({
controller: API
});
});
});
我知道木偶模塊已過時,所以請忽略,因爲我仍在測試Browserify。
問題是"": "showSearchOption"
路由沒有被觸發。
我的問題被提及在Marionette.AppRouter as Backbone.Router 我無法理解如何解決它?
編輯:
我覺得是,骨幹實例木偶內部使用不同於我所得到的,當我require('backbone')
。
對此問題的任何建議?
你確定Backbone.history.start()被調用嗎? –
你是什麼意思'木偶模塊已棄用'? – Kevin