【问题标题】:Backbone router : url visited directly no route match骨干路由器:直接访问的 url 没有路由匹配
【发布时间】:2015-03-12 20:18:18
【问题描述】:

我是 Backbone 的新手,遇到以下问题。

define([
'jquery',
'underscore',
'backbone',
'vm'
], function($, _, Backbone, Vm){
  'use strict';
  var AppRouter = Backbone.Router.extend({
    register: function(route, name, path) {

    this.route(route, name, function(){
      var args = arguments;
      require([path], function(module) {
        var options    = null,
            parameters = route.match(/[:\*]\w+/g);
        if (parameters) {
          options = {};
          _.each(parameters, function(name, idx) {
            options[name.substring(1)] = args[idx];
          });
        }
        var view = Vm.create(name, module, path);
        view.render();
      });
     });
    }
  });

  var initialize = function(){
     var appRouter = new AppRouter();

     appRouter.register('detail', 'detailView', 'views/detail/DetailView');

     appRouter.register('', 'HomeView', 'views/home/HomeView');

     Backbone.history.start({pushstate:true});
  };
  return {
    initialize: initialize
  };
});

上面是我的路由器,所以问题是当我直接访问 url localhost/detail 时,路由详细信息不匹配,而是匹配了空路由。

如果我手动添加一个 # (localhost/#detail) 到 url,它会匹配正确的路由。有人可以指出我正确的方向,这样我就可以直接加载与'/'不同的网址

【问题讨论】:

    标签: javascript backbone.js backbone-routing


    【解决方案1】:

    其实问题只是一个错字

    Backbone.history.start({pushstate:true});
    

    改为

    Backbone.history.start({pushState:true});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-26
      • 1970-01-01
      • 1970-01-01
      • 2016-03-31
      • 1970-01-01
      • 1970-01-01
      • 2013-10-16
      相关资源
      最近更新 更多