AngularJS How to remove # symbol in IE9 by using route

前端 未结 4 1013
夕颜
夕颜 2020-12-07 01:33

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/


        
相关标签:
4条回答
  • 2020-12-07 01:56

    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);
    }

    0 讨论(0)
  • 2020-12-07 02:00

    $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.

    0 讨论(0)
  • 2020-12-07 02:18

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

    0 讨论(0)
  • 2020-12-07 02:19

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

    RouterModule.forRoot(ROUTES, { useHash: Boolean(history.pushState) === false });
    
    0 讨论(0)
提交回复
热议问题