Angular UI-Router 无法使用 Internet Explorer 9 解析 [英] Angular UI-Router Not Resolving with Internet Explorer 9

查看:34
本文介绍了Angular UI-Router 无法使用 Internet Explorer 9 解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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).

为了解决任何其他路由,我尝试设置$locationProvider.html5Mode(false),修改了$locationProvider.hashPrefix,将<base href="/"/>改为各种网址,包括<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');
});

这篇关于Angular UI-Router 无法使用 Internet Explorer 9 解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆