Reloading the page gives wrong GET request with AngularJS HTML5 mode

前端 未结 24 3259
慢半拍i
慢半拍i 2020-11-22 01:39

I want to enable HTML5 mode for my app. I have put the following code for the configuration, as shown here:

return app.config([\'$routeProvider\',\'$location         


        
24条回答
  •  春和景丽
    2020-11-22 02:00

    From the angular docs

    Server side
    Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html)

    The reason for this is that when you first visit the page (/about), e.g. after a refresh, the browser has no way of knowing that this isn't a real URL, so it goes ahead and loads it. However if you have loaded up the root page first, and all the javascript code, then when you navigate to /about Angular can get in there before the browser tries to hit the server and handle it accordingly

提交回复
热议问题