AngularJS + html5Mode +自定义后备 [英] AngularJS + html5Mode + custom fallback
问题描述
我有一个具有 html5Mode = true 的应用程序,但是在IE上,我不需要回退到#/url .我需要保留URL并重新加载整个页面.
I have an application with html5Mode = true, but on IE I don't need to fallback to a #/url. What I need is to keep the URL and make a complete page reload.
如果找不到任何方法,则需要编辑AngularJS文件,这是我不想要的.
If I don't find any way, I will need to edit the AngularJS file, and that is what I don't want.
建议?
谢谢!
-编辑-
作为临时解决方案,我在AngularJS文件中注释了一些代码.
As a temporal solution I commented some code in the AngularJS file.
/*if ($sniffer.history) {*/
$location = new LocationUrl(
convertToHtml5Url(initUrl, basePath, hashPrefix),
pathPrefix, appBaseUrl);
/*} else {
$location = new LocationHashbangInHtml5Url(
convertToHashbangUrl(initUrl, basePath, hashPrefix),
hashPrefix, appBaseUrl, basePath.substr(pathPrefix.length + 1));
}*/
现在,它不再使用Hashtag网址了,如果浏览器不支持历史记录API,则Browser.url会创建一个 location.href .
Now it doesn't fall back to Hashtag urls, and the Browser.url make a location.href if the browser doesn't support the history API.
推荐答案
我认为这可以满足您的需求.如果不是,则解决方案可能涉及相同的事件 $ locationChangeStart
.
I think this does what you want. If not, perhaps the solution involves the same event $locationChangeStart
.
var gate = 1;
$scope.$on("$locationChangeStart", function(event, nextLocation, currentLocation) {
if ($('html').is('.ie6, .ie7, .ie8')) {
if (gate === 0) { //prevent endless location change
gate = 1;
window.location.href = nextLocation; //reload the page
}
else {
gate = 0;
}
}
});
如果您不知道此OldIE检查,请参阅此帖子.
In case you're unaware of this OldIE check, see this post.
这篇关于AngularJS + html5Mode +自定义后备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!