【发布时间】:2013-09-16 14:37:18
【问题描述】:
我正在尝试将主干.js 路由器与多页应用程序一起使用。
路由器可以正常使用默认路由,即 localhost,例如 "http://localhost:35970/"
或 www.myhompage.com"
但我想在具有以下路径的页面上使用骨干路由器:
"http://localhost:35970/customer/index"
让主干路由看起来像这样"
"http://localhost:35970/customer/index#create"
但它似乎不能以这种方式工作,我是否缺少任何东西让它在这样的路径上工作?
这是我的代码,谢谢:
var Router = Backbone.Router.extend({
routes: {
"Contact/Create": "create"
},
create: function () {
alert('router test');
}
});
//编辑
谢谢大家,这就是我所缺少的
root: "/customer/index/"
所以
Backbone.history.start({ pushState: true, root: "/customer/index/" })
我在没有指定根路径不是默认路径的情况下启动了历史记录
Backbone.history.start({ pushState: true })
因此问题。
【问题讨论】:
-
来自主干.js 文档:“如果您的应用程序不是从您的域的根 url / 提供服务,请务必告诉历史根的真正位置,作为一个选项:
Backbone.history.start({pushState: true, root: "/public/search/"})”