app.js
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
});
});
});
I am currently utilizing Browserify for testing purposes, so please disregard the fact that Marionette module is deprecated.
The current issue revolves around the "": "showSearchOption"
route not being triggered.
This problem has been mentioned in the following link: Marionette.AppRouter as Backbone.Router
and I am seeking guidance on how to resolve it.
Edit:
Initially, I believe that the internal Backbone instance utilized by Marionette differs from what is obtained when using require('backbone')
.
Any suggestions to tackle this issue?