我有一个使用require js
的骨干路由器。一切似乎都很好,但它不起作用。我从router
:
app.js
路由器JS:
define([
'jquery',
'underscore',
'backbone',
'view/questions/index'
], function($, _, Backbone, IndexView){
var AppRouter = Backbone.Router.extend({
routes: {
'/': 'index'
}
});
var initialize = function(){
var app_router = new AppRouter();
// Index Route
app_router.on('index', function(){
var indexView = new IndexView();
console.log('test');
indexView.initialize();
});
// Default Route
app_router.on('defaultAction', function(actions){
console.log('No Route', actions);
});
Backbone.history.start();
};
return {
initialize: initialize
};
});
App JS:
define([
'jquery',
'underscore',
'backbone',
'router'
], function($, _, Backbone, Router){
var initialize = function(){
Router.initialize();
};
return {
initialize: initialize
};
});
答案 0 :(得分:5)
伙计们我实际上有这个工作。以下是我在代码中所做的更改。
var AppRouter = Backbone.Router.extend({
routes: {
'': 'index'
}
});
在这里:
app_router.on('route:index', function(){
var indexView = new IndexView();
console.log('test');
indexView.initialize();
});