【发布时间】:2015-07-12 19:14:57
【问题描述】:
我有以下代码检查 pushstate 并在不受支持时降级为 hashbang (IE9):
if(Backbone.history && !Backbone.History.started) {
if(!(window.history && history.pushState)) {
Backbone.history.start({ pushState: false, silent: true});
var fragment = window.location.pathname.substr(
Backbone.history.options.root.length);
var search = window.location.search;
Backbone.history.navigate(fragment + search, { trigger: true });
}
else {
Backbone.history.start({ pushState: true });
}
}
它在功能上可以工作,但是 URL 是从以下位置转换的:
http://dev.zwoop.be/home?page=1
到
http://dev.zwoop.be/home?page=1#home?page=1
看起来很丑。
我正在寻找一个简单的修复方法,用主题标签替换主机名后面的整个片段。
【问题讨论】: