如何让哈希网址输出更干净的东西?它这样做:
domain.com /#/页面/ 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);
});
});
});
答案 0 :(得分:2)
尝试:
var url = "domain.com/#/page/1";
var noHash = url.split("/#").join("");
答案 1 :(得分:1)
这就是散列应该是什么样子 - #
部分是散列。如果您不想在网址中使用哈希,请执行以下操作:
window.location = link;
代替。
答案 2 :(得分:0)
if (location.href.indexOf("#") > -1) {
location.assign(location.href.replace(/\/?#\//, "/"));
}