【发布时间】:2014-05-10 21:52:43
【问题描述】:
您好,我正在创建一个 angularjs 应用程序。我将 $locationProvider.html5Mode 设为 true。现在我在没有 # 的情况下得到了漂亮的 url。它在 chrome 和 firefox 中运行良好。但是当我尝试在 IE 9 中打开它时,它会不断地重新加载。
【问题讨论】:
标签: html angularjs internet-explorer-9
您好,我正在创建一个 angularjs 应用程序。我将 $locationProvider.html5Mode 设为 true。现在我在没有 # 的情况下得到了漂亮的 url。它在 chrome 和 firefox 中运行良好。但是当我尝试在 IE 9 中打开它时,它会不断地重新加载。
【问题讨论】:
标签: html angularjs internet-explorer-9
坏消息。 IE9 不支持 HTML5 History API。这就是 angular html5Mode 使用的。如果您需要在 IE9 上运行您的应用程序,您需要切换回或添加代码以检测 History API 是否可用,使用是或默认为哈希
function supports_history_api() {
return !!(window.history && history.pushState);
}
我知道。愚蠢的IE。它应该死得很痛苦。
【讨论】:
$location 文档
参见“Hashband 和 HTML5 模式”
基本上,html5模式在浏览器支持时使用History API,在不支持时回退到hashbang(#)。
您不能在没有 History API 的浏览器中“仅仅”删除“#”。因为当您更改 url 时,浏览器会尝试强制重新加载,从而中断流程。
【讨论】: