如果浏览器不支持 History API,Ember 路由是否会回退到使用哈希? [英] Does Ember routing fall back to using a hash if browser doesn't support the History API?
问题描述
Ember 文档指出它可以设置为使用历史 API 进行路由而不是比基于哈希的片段使用:
Ember documentation states that it can be set to use the History API for routing rather than hash-based fragments by using:
App.Router.reopen({
location: 'history'
});
但是我没有提到如果浏览器不支持 History API 会发生什么.它会回退到使用像 History.js 这样的哈希吗?
But I can find no mention of what will happen if a browser doesn't support the History API. Will it fall back to using a hash like History.js?
如果不是,我是否应该检查 History API 支持并在不支持时将历史实现切换到哈希?
If not, should I check for History API support and switch history implementation to hash if it isn't supported?
推荐答案
ember 源中似乎没有任何 History API 支持检测.
There doesn't seem to be any History API support detection in the ember source.
因此,如果您将 location
设置为 history
,并且没有支持,则您的路由可能会失败.
So if you set location
to history
, and there's no support, your routing will probably fail.
如果您打算支持旧浏览器,最安全的选择就是您所说的:
If you intend to support old browsers, safest bet is like you said:
if (window.history && window.history.pushState) {
App.Router.reopen({
location: 'history'
});
}
2014 年 1 月 23 日更新
如果您在 Canary 中启用 ember-routing-auto-location
功能,您现在可以使用 location:'auto'
.
UPDATE 23 Jan 2014
You can now use location:'auto'
if you enable ember-routing-auto-location
feature in canary.
这篇关于如果浏览器不支持 History API,Ember 路由是否会回退到使用哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!