问题描述
我正在开发一个 Angular 4 网络应用程序,我需要使用 PathLocationStrategy
(而不是 HashLocationStrategy
).
I'm working on an Angular 4 web app and I need to use PathLocationStrategy
(not HashLocationStrategy
).
PathLocationStrategy
的唯一问题是,当我刷新页面时,我立即在控制台中看到一个空白页面,并显示 404 错误......这对于 PathLocationStrategy
来说是正常的.
The only problem with PathLocationStrategy
is that when I refresh a page, I instantly get a blank page with 404 errors in the console... Which is normal with PathLocationStrategy
.
一旦在服务器上,我就可以通过将路由重定向到 index.html 来解决这个问题.但是,当我使用 ng serve
启动我的应用程序时,如何在本地主机上解决这个问题?
Once on a server, I can fix that by redirecting the routes to point on index.html. But how to fix this issue on localhost when I launch my app with ng serve
?
这是理想的,因为我在livereload"中工作,因为当我更新文件时,我得到一个空白页面,我必须从基本路径重新启动.
It would be ideal since I'm working in "livereload", because when I update a file, I get a blank page and I have to restart from the base path.
那么在本地主机上工作时是否可以使用PathLocationStrategy
?
So is it possible to use PathLocationStrategy
when working in localhost?
推荐答案
ng serve
兼顾策略.在本地我使用 PathLocationStrategy
ng serve
take care of both Strategy. Locally I am using PathLocationStrategy
这篇关于如何在本地主机上使用 PathLocationStrategy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!