[英]Backbone router : url visited directly no route match
I am quite new to Backbone and I'm experiencing the following problem. 我对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
};
});
Above there's my router, so the problem is that when I visit directly the url localhost/detail the route detail is not matched, instead the empty route is matched. 上面是我的路由器,所以问题是当我直接访问url localhost / detail时,路由详细信息不匹配,而是匹配了空路由。
If I manually add a an # (localhost/#detail) to the url it works the correct route is matched. 如果我在网址中手动添加#(localhost /#detail),则可以匹配正确的路由。 Could someone point me in the right direction, so that I will be able to load directly an url that is different from '/'
有人可以指出正确的方向,这样我就可以直接加载不同于'/'的网址
Actually the problem was just a typo 其实问题只是错字
Backbone.history.start({pushstate:true});
changed to 变成
Backbone.history.start({pushState:true});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.