[英]Getting 404 error when Angular HTML5Mode is true
I have implemented pretty url in angular(switched to html5mode). 我已经在angular中实现了漂亮的URL(切换到html5mode)。
When I am refreshing the page I get 404 error. 当我刷新页面时,出现404错误。
For example: If I open my app using http://server/ , everything works fine,but when I refersh the page or try open specific page ex http://server/mypage , I get 404 error. 例如:如果我使用http:// server /打开我的应用程序,一切正常,但是当我引用该页面或尝试打开特定页面(例如http:// server / mypage)时 ,出现404错误。
Note: 注意:
And after compilation my scripts(with template) goes in build folder and base tag in index.html is set to "/";. 编译后,我的脚本(带有模板)进入构建文件夹,并且index.html中的基本标记设置为“ /”;。
I am using Angular-ui-router. 我正在使用Angular-ui-router。
Please suggest what could be the possible solution or reason for the error. 请提出可能的解决方案或错误原因。
Thanks 谢谢
You are should to check your settings in backend, when i am using html5 history, i have for this my .htaccess file (where you redirect all your requests to your root index.php or index.html file), look my .htaccess: 您应该检查后端的设置,当我使用html5历史记录时,为此我有.htaccess文件(您将所有请求重定向到根index.php或index.html文件),请查看我的.htaccess:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
if this not help, you are can to read this [article] 如果这没有帮助,您可以阅读此[文章]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.