我有一个带有许多不同选项的路由器,例如,我需要加载其中一个运行良好的路由,但是始终称为默认路由的默认路由会加载到一些其他模板中。
只是想知道是否有办法说如果在这种情况下这条路线 CMS,那么不要从默认路线加载元素。
来自我的路由器的代码:
define([
'jquery',
'underscore',
'backbone',
'views/common/header',
'views/common/menu',
'views/rightPanel',
'views/landing',
'views/personalBanking',
'views/currentAccounts',
'views/signIn',
'views/cms/cmsView',
], function($, _, Backbone, headerView, menuView, rightPanelView, landingView, personalBankingView, accountsView, signInView, CMS){
var AppRouter = Backbone.Router.extend({
currentView: null,
initialize: function() {
this.showView(headerView);
this.showView(menuView);
//TODO set for TV-width
if($(window).width() > 180) {
this.showView(rightPanelView);
}
},
routes: {
'': 'defaultAction',
'personal': 'showPersonalBankingView',
'accounts': 'showCurrentAccountsView',
'signIn': 'showSignInView',
'CMS': 'CMSView',
},
defaultAction: function(actions){
this.showView(landingView);
},
showPersonalBankingView: function(actions){
this.showView(personalBankingView);
},
showCurrentAccountsView: function(actions){
this.showView(accountsView);
},
showSignInView: function(actions){
this.showView(signInView);
},
CMSView: function(actions){
this.showView(CMS);
console.log("cms view going on");
},
showView: function(view) {
view.render();
if(view.postRender) {
view.postRender();
}
}
});
var initialize = function(){
new AppRouter();
Backbone.history.start();
};
return {
initialize: initialize
};
});
如果我解释得不够详细,请向我询问更多信息,期待一些帮助我对骨干很陌生。