AngularJS - 启用没有 404 错误的 HTML5 模式页面刷新错误、模式、页面、AngularJS

2023-09-06 08:23:32 作者:假烟假酒假朋友

我还尝试将 $locationProvider.html5Mode(true); 中的 ui-routing 和 base href 设置为 <base href="http://localhost/rootfoldername/"> 它会删除散列,但刷新时会出现 404 错误.

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.

请帮帮我...

推荐答案

正如其他人所说,启用 html5 模式并添加 baseURL 可以解决问题,但是仍然缺少一个难题,那就是服务器的重写规则配置.

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.

抛出 404 的原因是服务器没有将所有路由重定向到 angularJS 应用程序.这就是重写规则出现的地方.

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.

对于 apache:如何在 apache 中重写 urlangularjs 应用程序的 htaccess

对于 IIS:如何配置 IIS 以在 HTML5 模式下重写 AngularJS 应用程序的 URL?