[英]How to use PathLocationStrategy on localhost?
I'm working on an Angular 4 web app and I need to use PathLocationStrategy
(not HashLocationStrategy
). 我正在使用Angular 4 Web应用程序,并且需要使用PathLocationStrategy
(而不是HashLocationStrategy
)。
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
. PathLocationStrategy
的唯一问题是,当我刷新页面时,我立即在控制台中得到一个带有404错误的空白页面...这是PathLocationStrategy
正常PathLocationStrategy
。
Once on a server, I can fix that by redirecting the routes to point on index.html. 一旦在服务器上,我可以通过重定向路由以指向index.html来解决此问题。 But how to fix this issue on localhost when I launch my app with ng serve
? 但是,当我使用ng serve
启动我的应用程序时,如何在本地主机上解决此问题?
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. 因为我正在“ livereload”中工作,所以这将是理想的,因为当我更新文件时,我得到一个空白页,并且必须从基本路径重新启动。
So is it possible to use PathLocationStrategy
when working in localhost? 那么在本地主机上工作时可以使用PathLocationStrategy
吗?
ng serve
take care of both Strategy. ng serve
于两个策略。 Locally I am using PathLocationStrategy 我在本地使用PathLocationStrategy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.