Javascript 设置主干路由器
无法找出我的主干路由器出了什么问题。有人能发现下面代码块中的错误吗?索引路由工作正常,但类路由从未触发(例如,当我导航到类似Javascript 设置主干路由器,javascript,jquery,html,backbone.js,url-routing,Javascript,Jquery,Html,Backbone.js,Url Routing,无法找出我的主干路由器出了什么问题。有人能发现下面代码块中的错误吗?索引路由工作正常,但类路由从未触发(例如,当我导航到类似localhost/classes/test的URL时) 如果一切正常,我的代码中可能还有一个bug。默认情况下,路由将与哈希try localhost/#classes/test一起工作。默认情况下,路由将与哈希try localhost/#classes/test一起工作。路由器正在扩展哈希导航。 所以 localhost/#类/测试 应该引导你的方法。也!请注意,em
localhost/classes/test
的URL时)
如果一切正常,我的代码中可能还有一个bug。默认情况下,路由将与哈希try localhost/#classes/test一起工作。默认情况下,路由将与哈希try localhost/#classes/test一起工作。路由器正在扩展哈希导航。 所以 localhost/#类/测试 应该引导你的方法。也!请注意,emty路线应位于路线列表的末尾。
就像其他if构造一样,如果路由匹配“”(默认值?!),它将永远不会匹配其他路由主干网。路由器正在扩展hashbang导航。 所以 localhost/#类/测试 应该引导你的方法。也!请注意,emty路线应位于路线列表的末尾。 这与其他if构造类似,如果路由匹配“”(默认值?!),则它将永远不会匹配其他路由
var app = app || {};
$(function() {
app.Router = Backbone.Router.extend({
routes: {
'' : 'index',
'classes/:id' : 'classes'
},
initialize: function() {
this.classList = new app.ClassCollection();
},
index: function() {
this.menuView = new app.ClassCollectionView({collection: this.classList});
},
classes: function(id) {
console.log("hello")
var _class = new app.ClassModel({id: id});
this.classView = new app.ClassPageView({model: _class});
}
});
router = new app.Router();
Backbone.history.start({pushState: true});
})