
[英]Getting backbone routing to work with pushstate and node.js/express as server
[英]Backbone and pushstate with regards to server confuguration
我想就这个问题扩大我的问题 。 我能够使pushstate在Backbone应用程序中正常工作。 因此,当访问我的应用程序并导航链接时,我被重定向到localhost:8000 / page而不是localhost:8000 /#page。 现在我的问题在重新加载localhost:8000 / page时变得很明显。 显然我的服务器将抛出错误,因为它找不到指定的页面。 与localhost:8000 /#page相反,它将调用正确的路由。 现在说我的应用程序位于以下本地主机:8000 / index.html。 然后,我是否需要请求将所有路由重定向到localhost:8000 / index.html。 什么被认为是正确的方法? 我发现此要点是基于针对Backbone和pushstate的node.js服务器配置。 快速浏览,似乎所有请求都被重定向到应用程序文件(index.html)。 这个对吗? IIS有运气吗?
基本上,您需要在Apache或Nginx中使用一些重写规则。
Apache Vhost:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Nginx:
rewrite ^(.+)$ /index.html last;
对于实际的API调用,我在一个子域(例如api.site.com)上提供它们。 为此,您可能需要启用CORS。
我会在此博客条目中更深入地讨论它: http : //readystate4.com/2012/05/17/nginx-and-apache-rewrite-to-support-html5-pushstate/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.