Javascript 在url中使用hashbang解决IE9问题的替代方法
我正在使用以下设置在angularjs中创建搜索应用程序: 应用程序配置:Javascript 在url中使用hashbang解决IE9问题的替代方法,javascript,angularjs,url,internet-explorer-9,location-provider,Javascript,Angularjs,Url,Internet Explorer 9,Location Provider,我正在使用以下设置在angularjs中创建搜索应用程序: 应用程序配置: app.config( [ '$locationProvider', function ($locationProvider) { $locationProvider.html5Mode({ enabled: true, requireBase: false,
app.config(
[
'$locationProvider',
function ($locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
rewriteLinks: false
});
}
]
);
问题不在于应用程序本身,而是当我试图使用IE9访问页面时,我根本无法访问它。在阅读som之后,我发现IE9忽略了url中#之后的所有内容,并将用户重定向回主机url(url中#之前的所有内容),HTML5模式的标准回退方式是hashbang模式 我的问题是,是否有人知道在url中使用hashbang有什么办法,或者其他人是否有这个问题。如果需要更多的文档,请让我知道,我会提供 编辑:这在控制器内部:
$scope.$on('$locationChangeSuccess', function () {;
$scope.searchQuery = $location.search()['q'];
$scope.search();
});
编辑:
添加$locationProvider.hashPrefix(“!”)代码>将不起作用,因为它只会在url中的“#”之后添加一个“!”
请参见角度文档中的图像:
IE9不支持历史记录。请参阅:
因此,当您启用HTML5模式时,例如:$locationProvider.html5模式(true)
对于IE9,它将退回到URL中的#,这是无法避免的
已经说过,您应该仍然能够使用$location.search()代码>
您可以获得如下搜索参数:
var searchObject=$location.search()代码>
要获取特定参数,可以执行以下操作:$location.search().paramName
有关更多信息,请参阅$location
$location
服务的替代方法是注入$routeParams
,请参阅:$routeParams
但我不确定您的使用情况,路由图只有在路由更改完成后才会更新“在阅读som之后,我发现IE9忽略了url中#之后的所有内容,并将用户重定向回主机url”。URL中的哈希就是这样工作的。Angular的工作原理是将其解析为一个内部可用的url。那么,问题是什么?为什么你不能在IE9中访问它?你做过故障排除吗?回退是正确的,正如我们在文档中看到的。我启用了HTML5模式,但在IE9中,我的应用程序陷入了无限直接循环。如何使回退URL正常工作?