Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 设置主干路由器_Javascript_Jquery_Html_Backbone.js_Url Routing - Fatal编程技术网

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});
})