如何讓散列網址輸出更清潔的東西?它這樣做:從網址去除散列號
domain.com/#/page/1
當我想它這樣做:
domain.com/page/1
$(document).ready(function(){
var newHash = '';
$('#wrapper a').live('click', function(e){
if (this.hostname && this.hostname == location.hostname) {
e.preventDefault();
var link = $(this).attr('href');
window.location.hash = link;
}
});
$(window).bind('hashchange', function() {
newHash = window.location.hash.substr(1);
$('#content').fadeOut(100).load(newHash + ' #contentInner', function(){
$('#content').fadeIn(100);
});
});
});
這些是兩個完全不同的URL。他們指向不同的資源。第一個指向domain.com默認索引,第二個指向domain.com的/ page/1。散列前的所有內容都描述了資源名稱和可選參數,並且之後的所有內容都是客戶端通常處理的資源的錨點。 – jiggy
如果我正確地理解了你,你需要[HTML5歷史API](http://diveintohtml5.org/history.html)來完成這件事。 –