例如,我有一个网站domain.com。我有带有pushstate和后备功能的backbone.js,当我转到domain.com/about时,它会加载index.html页面并将pushstates到about。一切正常。但是,如果我想转到一个包含页面的目录,例如:www.domain.com/bio/moreinfo,它不起作用并抛出无效页面。如果我在 IE 中这样做它工作正常。我的 htaccess 文件具有以下内容:
RewriteEngine on
# html5 pushstate (history) support:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>
如果我直接导航到页面domain.com/bio/moreinfo,它就会崩溃(我想是因为我的服务器想要转到bio目录?或者也许我需要实际以不同的方式控制主干中的路由?只是它适用于刘海所以它必须是一些奇怪的推送状态目录,其中 #bio/info 与 apache 的 /bio/info 不同。感谢任何帮助。
很好地使用了另一篇建议帖子中的答案,这是要做的<base href="/" />
在index.html 文件中。这实际上使我的 PushState 中的子目录工作了!只是有人建议..但作为回报,它破坏了我的 IE,但我通过在主干的 INIT 中添加额外的代码来修复它
Backbone.history.start({ pushState: Modernizr.history, silent: true });
if(!Modernizr.history) {
var rootLength = Backbone.history.options.root.length;
var fragment = window.location.pathname.substr(rootLength);
var search = window.location.search;
Backbone.history.navigate('/#' + fragment + search, { trigger: true });
} else {
Backbone.history.loadUrl(Backbone.history.getFragment())
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)