我的路由器:
var Backbone = require('backbone'),
headerView = require('./views/header/HeaderView'),
sidebarView = require('./views/sidebar/SidebarView'),
footerView = require('./views/footer/FooterView'),
dashboardView = require('./views/dashboard/DashboardView'),
channelListView = require('./views/channel/ChannelListView');
var Router = Backbone.Router.extend({
initialize: function() {
var header = new headerView();
header.render();
var sidebar = new sidebarView();
sidebar.render();
var footer = new footerView();
footer.render();
},
routes: {
"*actions": "home",
"channel": "channelIndex"
},
home: function() {
"use strict";
var dash = new dashboardView();
dash.render();
},
channelIndex: function() {
"use strict";
var channelListView = new channelListView();
channelListView.render();
},
});
module.exports = Router;
查看:
var $ = require('jquery'),
jQuery = require('jquery'),
Backbone = require('backbone'),
Handlebars = require('handlebars'),
jQueryFunctions = require("../../libs/jqueryfunctions"),
sidebarTemplate = require("../../templates/sidebar/sidebar.html");
module.exports = Backbone.View.extend({
el: '#sidebar-wrapper',
// Listen for when the user clicks our anchor tag
events: {
'click #id-open-channel-list': 'channelList'
},
channelList: function(e) {
e.preventDefault();
Backbone.history.navigate('/channel', {
trigger: true
});
},
render: function() {
"use strict";
this.facilityName = sessionStorage.getItem('FacilityName');
this.$el.html(sidebarTemplate({
facilityName: this.facilityName
}));
}
});
当我点击链接时,它只是刷新页面不会调用路径。