5

I'm creating a search application in angularjs with these settings:

App Config:

    app.config(
    [
        '$locationProvider',
        function ($locationProvider) {
            $locationProvider.html5Mode({
                enabled: true,
                requireBase: false,
                rewriteLinks: false
            });
        }
    ]
);

The problem is not the app itself but when im trying to access the page with IE9 im not able to access it at all. After doing som reading i found out that IE9 ignores everyting that comes after the # in an url, and redirects the user back to the host url (everything before the # in the url) And the standard fallback for html5mode is hashbang-mode. Angular docs for $location

My question is if anyone knows if there is any way around the use of hashbangs in the url or if anyone else have this problem. If more documentation is needed, please let me know and i will provide!

EDIT: This is inside the controller:

    $scope.$on('$locationChangeSuccess', function () {;
        $scope.searchQuery = $location.search()['q'];
        $scope.search();
    });

EDIT: Adding $locationProvider.hashPrefix('!'); will not work because it will only add a "!" after the "#" in the url.

See image from angular docs:

Angular docs on locationprovider

4

1 回答 1

0

IE9不支持history.pushState,见:http ://caniuse.com/#feat=history

因此,当您启用 html5Mode 时,例如:$locationProvider.html5Mode(true) 对于 IE9,它将回退到 URL 中的 # - 没有办法解决这个问题

话虽如此,您应该仍然可以使用$location.search(); 您可以像这样获取搜索参数: var searchObject = $location.search(); 要获取特定参数,您可以执行以下操作:$location.search().paramName

有关详细信息,请参阅https://docs.angularjs.org/api/ng/service/$location

该服务的替代方法$location是注入$routeParams,请参阅:https : //docs.angularjs.org/api/ngRoute/service/ $routeParams 但我不确定您的用例,routeParams 仅在路线更改完成后更新

于 2015-05-15T16:03:49.437 回答