AngularJS - Enable HTML5 Mode Page Refresh Without

2019-01-09 19:33发布

This question already has an answer here:

I also tried by setting the $locationProvider.html5Mode(true); in ui-routing and base href to <base href="http://localhost/rootfoldername/"> it removes hash but on refresh it gives 404 Error.

Please help me out...

1条回答
祖国的老花朵
2楼-- · 2019-01-09 20:04

As others said enabling html5 mode and adding a baseURL does the trick, however one piece of the puzzle is still missing and thats the rewrite rules configuration for your server.

The reason why the 404 is thrown is because the server doesn't redirect all routes to the angularJS app. This is where rewrite rules come on.

For apache: How to rewrite url in apache htaccess for angularjs app

For IIS: How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?

查看更多
登录 后发表回答