AngularJS - 在没有 404 错误的情况下启用 HTML5 模式页面刷新 [英] AngularJS - Enable HTML5 Mode Page Refresh Without 404 Errors

查看:27
本文介绍了AngularJS - 在没有 404 错误的情况下启用 HTML5 模式页面刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还尝试通过将 ui-routing 和 base href 中的 $locationProvider.html5Mode(true); 设置为 <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:如何为 HTML5 模式下的 AngularJS 应用程序的 URL 重写配置 IIS?

这篇关于AngularJS - 在没有 404 错误的情况下启用 HTML5 模式页面刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆