apache服务器中的angular 4部署包刷新错误服务器
目前,我的 Angular 应用程序在 'http://localhost' 根或索引页,但刷新内页时 'http://localhost/dms-data/summary-of-findings' 然后显示浏览器
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/summary-of-findings.
Apache/2.4.9 (Win32) PHP/5.5.12 服务器在本地主机端口 80
我的浏览器中的这条消息我的 index.html base href 是
this message in my browser my index.html base href is
<base href="http://localhost/">
这是因为您使用 HTML pushState 作为定位策略,当您从浏览器刷新时,浏览器会将路由页面的请求发送到 apache 服务器.由于 apache 服务器显示 404 错误,因此 angular 不知道此内部路由.
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:
将回退页面定义为 index.html:您需要在服务器中进行配置,因为任何未知页面请求(即您的路由请求)发送到您的服务器都将被重定向到你的主要 html 可视化.index.html(请参阅此链接以配置您的服务器)
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)