Backbone.js的PushState航线的.htaccess只​​是工作作为哈希,但无处 [英] Backbone.js PushState routes .htaccess only working as hash but nowhere else

查看:178
本文介绍了Backbone.js的PushState航线的.htaccess只​​是工作作为哈希,但无处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站domain.com为例。我有Backbone.js的与pushstate和回退,当我转到domain.com/about它index.html页面和pushstates加载了约。一切工作。但如果我想转到里面像一个网页目录:www.domain.com/bio/moreinfo例如,它不工作,并抛出一个无效页。如果我做它在IE浏览器正常工作。我的htaccess文件有以下内容:

I have a website domain.com for example. I have backbone.js with pushstate and fallback and when I goto domain.com/about it loads up the index.html page and pushstates to about. everything is working. but if i want to goto a directory with a page inside like: www.domain.com/bio/moreinfo for example, it does not work and throws a invalid page. if i do it in IE it works fine. my htaccess file has the following:

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它胡扯了(我想是因为我的服务器要转到这个生物目录?或者我需要实际控制骨干网的路由不同?它只是它适用于刘海所以它必须有一些怪异的推状态目录下的东西,其中#生物/信息是不一样的,以Apache作为/生物/信息。任何帮助是AP preciated。

if i navigate directly to the page domain.com/bio/moreinfo it craps out (i think because my server wants to goto the bio directory? or maybe I need to actually control the routes in backbone differently? its just that it works on bangs so it has to be some weird push state directory thing where #bio/info is not the same to apache as /bio/info . any help is appreciated.

推荐答案

使用的答案在另一个建议后,这是要做好     &LT;基地的HREF =//&GT; 在index.html文件。这实际上提出的子目录我pushState的工作!只是有人建议..但随后在返回它打破了我的IE浏览器,但我固定它通过把额外的code。在我的骨干INIT

well using the answer in another suggested post, which was to do <base href="/" /> in the index.html file. This actually made the sub directories in my pushState work! just it was suggested.. but then in return it broke my IE, but i fixed it by putting extra code in my INIT of backbone

 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())
}

这篇关于Backbone.js的PushState航线的.htaccess只​​是工作作为哈希,但无处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆