Alternative to using hashbangs in url to resolve IE9 problem

I am 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 with the application itself, but when I try to access a page with IE9, I could not access it at all. After I read som, I found out that IE9 ignores everything that comes after # in the URL, and redirects the user back to the host URL (everything up to # in the URL). And the standard reserve for html5mode is hashbang-mode. Angular docs for $ location

My question is, does anyone know if there is a way to use hash bands in the url, or if anyone else has this problem. If additional documentation is required, let me know and I will provide!

EDIT: 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 "!" after the "#" in the url.

See image from angular docs:

Angular docs on locationprovider

+5
source share
1 answer

IE9 does not support history.pushState, see http://caniuse.com/#feat=history

Therefore, when you enable html5Mode, for example: $locationProvider.html5Mode(true) For IE9, it will be dropped to # in the URL - there is no way

Having said that, you can still use $location.search(); You can get the search parameters as follows: var searchObject = $location.search(); To get a specific parameter, you can do: $location.search().paramName

See https://docs.angularjs.org/api/ng/service/ $ for more details.

An alternative to the $location service is to enter $routeParams , see https://docs.angularjs.org/api/ngRoute/service/ $ routeParams But I'm not sure about your use case, routeParams are updated only after changing the route

0
source

Source: https://habr.com/ru/post/1212446/


All Articles