Internet Explorer 9 无法解析 Angular UI-RouterExplorer、Internet、Angular、Router

2023-09-06 08:59:17 作者:一輩子的守護

我有一个 Angular v1.3 应用程序,它使用 Angular ui-router v0.2.13 进行所有路由.该网站适用于所有浏览器,包括 IE 10 和 IE 11,但不是 IE 9(我们决定不使用 IE8,我知道 v1.3 不支持它).尽管我尽了最大的努力,IE 9 仍不断解析我的 $stateProvider's otherwise 路由(设置为 /*path,这可能是罪魁祸首,所以我出于测试目的禁用了该路线).

I have an Angular v1.3 application, which uses Angular ui-router v0.2.13 for all routing. The site works great on all browsers, including IE 10 and IE 11, but not IE 9 (we've decided not to pursue IE8, which I understand isn't supported by v1.3, anyway). Despite my best efforts, IE 9 continually resolves to my $stateProvider's otherwise route (which is set to /*path, a possible culprit, so I disabled that route for testing purposes).

为了让 any 其他路由来解决,我尝试设置 $locationProvider.html5Mode(false),修改了 $locationProvider.hashPrefix,将<base href="/"/>改为各种URL,包括<base href="/#!"/>,我什至在 <html> 标记中包含了 xmlns:ng="http://angularjs.org" 以进行良好的衡量.无论我尝试什么,IE 9 都会不断尝试解析我的 otherwise 路由,或者如果该路由被禁用,则什么也不做.顺便说一句,我的主页路由 URL 设置为 /.

In an attempt to get any other route to resolve, I've tried setting $locationProvider.html5Mode(false), modified the $locationProvider.hashPrefix, changed the <base href="/" /> to various URLs, including <base href="/#!"/>, and I've even included xmlns:ng="http://angularjs.org" in the <html> tag for good measure. No matter what I try, IE 9 continually tries to resolve to my otherwise route, or nothing if that route is disabled. BTW, my home page route URL is set to /.

在发布截止日期迫在眉睫的情况下,我一直在关注我的代码,所以我会第一个承认我可能会忽略一些明显的东西.谁能提供任何其他提示或技巧以使 ui-router 在 IE 9 中正确解析?

I've been up to my eyeballs in code with a launch deadline looming, so I'll be the first to admit that I'm potentially overlooking something obvious. Can anyone offer any other tips or tricks to cause ui-router to resolve properly in IE 9?

推荐答案

对我来说,IE9 正确路由哈希 URL,/#/example,但访问 / 会解决其他路线.我通过使用一个函数来解决这个问题,并检查其中的 url.

For me, IE9 routes correctly for hash urls, /#/example, but visiting / would resolve to the otherwise route. I worked around this by using a function for otherwise, and checking the url in it.

$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');
});