如何在angularjs中禁用IE8和IE9上的#hashbang重定向

时间:2014-07-17 07:38:42

标签: angularjs hashbang

我有一个angularjs(v 1.2.19)应用程序,它由两个独立的html页面组成(或者实际上这些是两个单独的angularjs应用程序在一个文件夹中):

  • 的index.html
  • edit.html

我在IE 8和9上有一些众所周知的兼容性问题(两者都不支持html5历史API)。 我的配置包含:$locationProvider.html5Mode(true).hashPrefix('!');

我在应用程序中没有任何路由 - index.html和edit.html可以看作是单独的angularjs应用程序 - 具有单独的angularjs初始化等。

问题如下: 每当我打开链接时:http://server/apphttp://server/app/index.html一切正常。

每当我打开链接:http://server/app/edit.html来自ng-click或直接在浏览器中,页面会自动重定向到http://server/#!app/edit.html

如何禁用“hashbang”重定向? Edit.html不是index.html的一部分,因此它应该直接加载,不需要任何index.html重定向和“哈希”路由。

我尝试了下面的代码,但它会导致无限循环的重定向......

<!--[if lt IE 10]>
    <script>   
        window.location = window.location.href.replace( /#.*/, "");
    </script>
<![endif]-->

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:-1)

尝试禁用html5mode $locationProvider.html5Mode(false).hashPrefix('!'); 或完全删除此字符串。