2013-01-23 37 views
3

我有一個網站domain.com爲例。我有backbone.js pushstate和fallback,當我goto domain.com/about時,它加載了index.html頁面並推送到about。一切正常。但如果我想轉到一個內部頁面如:www.domain.com/bio/moreinfo例如,它不起作用,並引發無效頁面。如果我在IE中這樣做,它工作正常。我htaccess文件有以下幾點:Backbone.js PushState路由.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它胡扯出來(我想是因爲我的服務器要轉到這個生物目錄,或者也許我需要實際?控制骨幹路由的方式不同嗎?它只是它在劉海運行,所以它必須是一些奇怪的推狀態目錄的事情,其中​​#生物/信息是不一樣的阿帕奇作爲/生物/信息任何幫助表示讚賞。

+0

昨天出現了同樣的問題一個家​​夥,固定它除了他正在上的一切,但* * IE。一起你有一個工作路由器,恭喜。 http://stackoverflow.com/questions/14469467/backbone-history-deep-urls-are-not-falling-backing-properly-in-ie – jevakallio

回答

2

很好地使用了另一個建議的帖子中的答案,在index.html文件中做 <base href="/" /> 。這實際上使我的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()) 
} 
相關問題