0

我有一个 AngularJS 应用程序,其中包含所有常见的 IE 解决方法:

<html id="ng-app" class="ng-app:clientsite" ng-app="clientsite" xmlns:ng="http://angularjs.org">
    <head>
        <!--[if lt IE 9]>
          <script src="js/html5.js"></script>
        <![endif]-->
        <!--[if lte IE 8]>
          <script>
            document.createElement('ng-include');
            document.createElement('ng-pluralize');
            document.createElement('ng-view');
            document.createElement('ng:include');
            document.createElement('ng:pluralize');
            document.createElement('ng:view');
          </script>
        <![endif]-->
        <!--[if lt IE 8]>
          <script src="js/json2.js"></script>
        <![endif]-->

该站点有效,我可以到达任何路线,除了 IE7 没有选择空路线“/”:

$routeProvider
.when("/",
{
    templateUrl: "/htm/home.htm"
})

它正在路由到我的其他路线:

.otherwise(
{
    templateUrl: "/htm/notfound.htm"
});

如果我在路线末尾添加 /#/,它会起作用,但我们的客户不会接受(人们需要能够直接访问 www.theirsite.com,我们不能要求 www.theirsite .com/#/)。

在幕后,我有一个 ASP.Net MVC 服务器,它只是将所有内容路由回我的索引文件(它可以全面工作,除了 IE7 中的这条路由)。

如何让空路由在 IE7 中正常工作?

4

1 回答 1

0

我有一个类似的问题,这就是我解决它的方法:

.otherwise({
    templateUrl: '/app/error.html',
    resolve: {
        // Here we ensure that our route has the document fragment (#), or more specifically that it has #/ at a minimum.
        // If accessing the base URL without a trailing '/' in IE7 it will execute the otherwise route instead of the signin
        // page, so this check will ensure that '#/' exists and if not redirect accordingly which fixes the URL.
        redirectCheck: ['$location', function ($location) {
            var absoluteLocation = $location.absUrl();

            if (absoluteLocation.indexOf('#/') === -1) {
                $location.path('/');
            }
        }]
    }
});
于 2013-10-17T19:25:27.073 回答