AngularJS How to remove # symbol in IE9 by using route

∥☆過路亽.° 提交于 2019-12-17 16:58:06

问题


I can't remove the # symbol in IE9. I searched for an answer but didn't find a fix.

This always redirects to

http://myhost.com:8080/#/website/

and shows this description:

The requested resource is not available.

locationprovider.html5mode(true) is not working. The same route is working in FireFox and shows

http://myhost.com:8080/website/

How can I rectify this?


回答1:


IE9 does not have html5 history api support, that's why it's appending # to the url, removing # will not solve your problem




回答2:


$location Documentation

See "Hashbang and HTML5 modes"

Basically, html5 mode uses History API when the browser supports it, and falls back to hashbang(#) when it is not supported.

You cannot "just" remove "#" in a browser without History API. Because when you change the url, the browser would then try to force a reload, breaking the flow.




回答3:


In fact we can not remove that, but we can make it work smoothly

RouterModule.forRoot(ROUTES, { useHash: Boolean(history.pushState) === false });



回答4:


Using window.location.hash = '/' solved my problem.

if (window.history && window.history.pushState) {
  $locationProvider.html5Mode(true);
}
else {
        window.location.hash = '/'  // IE 9 FIX            
        $locationProvider.html5Mode(true);
}


来源:https://stackoverflow.com/questions/17829991/angularjs-how-to-remove-symbol-in-ie9-by-using-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!