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

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

问题描述

我也尝试了将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:

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

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

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

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