2013-04-23 83 views
0

我使用Asual的jQuery地址插件在不使用哈希的情況下(使用HTML5 History API)在內容之間進行深度鏈接。jQuery地址無法刷新

這裏是我的代碼:

$.address.state("/").init(function(e){ 
    $('#nav li a').address(); // initializes 
    if (e.value == "/") { 
     $.address.value("/home"); // loads /home by default 
    }; 
}); 

$.address.change(function(e) { 
    // loads whatever page is in that /pages folder and puts the content in div#container 
    $.get("/pages" + e.value + ".html", function(data, textStatus, xhr) { 
     $('#container').html(""); //clears out the old content 
     $('#container').html(data); //loads the new page in there 
    }); 
}); 

點擊頂部導航按鈕時,這個完美的作品。即使瀏覽器中的後退和前進按鈕也像魅力一樣。問題是刷新/打開另一個選項卡中的網址。 例如,如果我寫http://domain.com它會讓我到http://domain.com/home並顯示內容。如果我刷新我得到一個404錯誤。瀏覽器正在尋找一個當然不存在的實際/ home文件(改爲home.html)。

任何想法? 謝謝!

DD

+0

您是否曾經爲此找到過解決方案? – 2013-10-24 21:57:06

回答

0

我試圖做同樣的事情,並得到同樣的問題,結束使用哈希。