【发布时间】:2012-05-27 18:31:25
【问题描述】:
我们正在开发一个 Backbone.js 应用程序,我们可以通过键入 python -m SimpleHTTPServer 来启动 HTTP 服务器这一事实非常棒。
我们希望能够将任何 URL(例如 localhost:8000/path/to/something)路由到我们的 index.html,以便我们可以使用 HTML5 pushState 测试 Backbone.Router。
实现这一目标最轻松的方法是什么? (为了快速制作原型)
【问题讨论】:
-
localhost/path_to_nowhere将引导您到nowhere。但是localhost/path/somewhere_in_nowhere可以按照您的预期将您带到任何地方。要将任何 url 路由到端点(目标 url),您必须首先加载包含主干、下划线、jquery 的页面,对吗?您还应该引导一个路由到端点 url 的路由器。 -
我想你误解了我的问题。当您在启用 pushState 的 Backbone 应用程序中时,您的 URL 将在您浏览您的应用程序时更改为
http://localhost:8000/some/path/in/my/app。但是对于 SimpleHTTPServer,如果此时刷新页面,您将收到 404,因为服务器会尝试获取该 URL 的资源。我正在寻找一种方法来允许服务器将任何 URL 重新路由回index.html。
标签: backbone.js prototyping httpserver simplehttpserver backbone-routing