Apache服务器中的Angular 4部署程序包刷新错误服务器 [英] angular 4 deployment package refreshing error server in apache server

查看:105
本文介绍了Apache服务器中的Angular 4部署程序包刷新错误服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我的角度应用程序在' http://localhost '根目录下运行apache服务器索引页,但是在刷新内页时' http://localhost/dms-data/summary-发现",然后显示浏览器

Currently, my angular app run apache server in 'http://localhost' root or index page, but when refreshing the inner page 'http://localhost/dms-data/summary-of-findings' then show browser

未找到

在此服务器上找不到请求的URL/dms-data/find-of-findings.

Apache/2.4.9(Win32)PHP/5.5.12服务器(位于本地主机端口80)

此消息在我的浏览器中 我的index.html基本href是

this message in my browser my index.html base href is

<base href="http://localhost/">

推荐答案

这是因为您使用HTML pushState作为位置策略,因此从浏览器刷新时,浏览器会将路由页面的请求发送到apache服务器.由于apache服务器由于显示404错误,因此无法通过角度了解此内部路由.

This is because you are using HTML pushState as location strategy due to which when you refresh from browser, the browser sends request of your routed page to apache server. As apache server is unaware of this internal routing by angular due to it shows 404 error.

有两种可能的解决方案:

There are two possible solutions for this:

  1. 将后备页面定义为index.html :您需要在服务器中进行配置,因为发送到服务器的任何未知页面请求(即路由请求)都将被重定向到您的主要HTML视觉. index.html(请参阅此链接以配置您的服务器)

  1. Define fallback page as index.html: You need to configure this in server due to which any unknown page request (which is your routed request) send to your server will be redirected to your main html viz. index.html (See this link for configuring your server)

使用基于哈希的位置策略:使用此方法,您不需要任何服务器配置.此外,您的路由页面URL类似于localhost/#/route1.如果您要建立一个网站,那么它也可能会阻碍SEO. (请参阅此链接以获取更多信息)

Use Hash based location strategy: Using this you won't need any server configuration.Moreover your routed page URL would be like localhost/#/route1. If you're building a website then it may also hamper SEO. (See this link for more info)

这篇关于Apache服务器中的Angular 4部署程序包刷新错误服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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