Kha*_*ngh 4 history.js pushstate ember.js
我正在使用ember应用程序(使用ember-1.0.pre.js).我正在尝试在IE8上提供跨浏览器兼容性.
问题是在每次转换后生成url,对用户来说似乎不正确/错误.假设我点击了the_ domain_name/sell/new我们应用程序的销售页面上最初登陆的网址 .然后我试图通过一个名为"购买"的新状态,这将使我登陆我们的应用程序的购买页面.
新的状态转换在IE8地址栏中生成一个URL ,而不是.the_ domain_name/sell/new#/offers/purchase?&suid=1365149991779013736531657156165the domain_name/offers/purchasehttp://www.example.com
注意: the_domain_name =the_ domain_name/sell/new
生成的网址包含两个不正确的内容,
初始前缀"/ sell/new#".
url的查询字符串中的参数"?&_ suid = 1365149991779013736531657156165".
我试图找出问题,发现HTML4浏览器不支持HTML5中的History API中的pushState和replaceState方法.我如何在IE8上提供支持任何人都可以帮助我吗?
inD*_*eam 11
我建议History.js不支持历史API的浏览器使用polyfill:https: //github.com/browserstate/history.js
它的工作原理是:
HTML5浏览器:
HTML4浏览器:
添加jquery.history.js并history.js在Ember App中注册位置处理程序.
这是我从原始修改的部分Ember.HistoryLocation(完整代码)
(function() {
var get = Ember.get, set = Ember.set;
var popstateFired = false;
Ember.HistoryJsLocation = Ember.Object.extend({
initState: function() {
this.replaceState(this.formatURL(this.getURL()));
set(this, 'history', window.History);
},
getState: function() {
return get(this, 'history').getState().state;
},
pushState: function(path) {
History.pushState({ path: path }, null, path);
},
replaceState: function(path) {
History.replaceState({ path: path }, null, path);
}
});
Ember.Location.registerImplementation('historyJs', Ember.HistoryJsLocation);
})();
Run Code Online (Sandbox Code Playgroud)
然后在您的App中使用此polyfill:
App.Router.reopen({
location: 'historyJs'
});
Run Code Online (Sandbox Code Playgroud)