Angular UI-Router在Internet Explorer 9中无法解析

8
我有一个Angular v1.3应用程序,使用Angular ui-router v0.2.13进行所有路由。该网站在所有浏览器上都工作良好,包括IE 10和IE 11,但不包括IE 9(我们决定不追求IE8,我了解到v1.3不支持它)。尽管我已经尽力了,IE 9仍然不断地解析到我的$ stateProvider的otherwise路由(设置为/*path,是可能的罪犯之一,因此我为测试目的禁用了该路由)。
为了尝试让任何其他路由解析,我尝试设置$ locationProvider.html5Mode(false),修改$ locationProvider.hashPrefix,将更改为各种URL,包括,并且我甚至在标签中包含xmlns:ng =“http://angularjs.org”以确保万无一失。无论我尝试什么,IE 9都会不断尝试解析到我的otherwise路由,或者如果该路由被禁用,则什么也不做。顺便说一句,我的主页路由URL设置为/。
我一直在忙于代码,发现启动期限逼近,所以我首先承认自己可能忽略了一些明显的东西。还有人能提供其他提示或技巧来使ui-router在IE 9中正确解析吗?
2个回答

0
我们通常使用类似以下的内容:
<!DOCTYPE html>
  <html lang="fr" xmlns="http://www.w3.org/1999/xhtml" ng-csp xml:lang="fr-CA">

//...
var app = angular.module('YourApp', [...]);
angular.bootstrap(document, ['YourApp'], {strictDi: true})

//...
    angular.module('YourApp').config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
  function ($stateProvider, $urlRouterProvider, $locationProvider) {
    $locationProvider.html5Mode(false);
    $locationProvider.hashPrefix('!');

    $urlRouterProvider.otherwise('/');

    $stateProvider
      .state('home', {
        url: '/',
        cache: false,
        controller: 'HomeController as vm'
      })
      .state('anon', {
        url: '/info',
        controller: 'AnonController as vm'
      })

//等等...


0

对我来说,IE9可以正确地路由哈希URL,/#/example,但访问/会解析为其他路由。我通过使用一个otherwise函数并在其中检查URL来解决了这个问题。

$urlRouterProvider.otherwise(function($injector){
    var state = $injector.get('$state');
    var location = $injector.get('$location');
    if (!location.url()) {
        // handle HTML5 fallback / IE9 when url has no hash
        return state.go('home');
    }
    state.go('404');
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接