问题描述
我正在使用Angular 4 Web应用程序,需要使用 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服务
兼顾了这两种策略.我在本地使用PathLocationStrategy
ng serve
take care of both Strategy. Locally I am using PathLocationStrategy
这篇关于如何在本地主机上使用PathLocationStrategy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!