【发布时间】:2012-12-02 02:40:24
【问题描述】:
我已经定义了
var AppRouter = Backbone.Router.extend({
routes: {
"photos/": "showPhotos",
"pic/:object_id": "getPic"
//"*actions": "defaultRoute"
},
showPhotos: function() {
console.log("routing: showPhotosPage");
App.showPhotosPage();
},
我还确保启动并启动路由器...
// Initiate the router
var app_router = new AppRouter();
// Start Backbone history
Backbone.history.start();
当我将浏览器指向 localhost/~myusername 时,获取要加载的页面和脚本(通过查看 firebug)。但是,如果我将浏览器指向 localhost/~myusername/photos/photos/,则会出现以下浏览器错误。
未找到 在此服务器上找不到请求的 URL /~jayc707/moments/。
我正在使用 Apache 运行 Mountain Lion。
谢谢!
【问题讨论】:
-
试试 localhost/~myusername/#/photos
-
有效!谢谢。我应该如何修改我的路线以使 localhost/~myusername/photos 有效?
-
我不相信你能做到。
-
在
Backbone.history.start调用中使用pushState: true(backbonejs.org/#History-start) 请注意,当用户重新加载页面时,Web 服务器会提供初始请求,因此请确保它返回有意义的内容。
标签: javascript apache backbone.js routes