简体   繁体   English

如何在本地主机上使用PathLocationStrategy?

[英]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.

相关问题 如何在Spring Boot应用程序中使用Angular2 PathLocationStrategy? - How can I use Angular2 PathLocationStrategy in a Spring Boot application? Angular PathLocationStrategy 在 localhost:4200 上刷新 url - Angular PathLocationStrategy refresh url on localhost:4200 如何使 angular 中的路径定位策略在已部署的网站上工作? - how to make pathlocationstrategy in angular work on deployed website? Angular:一些路由使用PathLocationStrategy,但其他一些路由使用HashLocationStrategy - Angular: Some routes use PathLocationStrategy but some other routes use HashLocationStrategy 如何在 angular 中使用本地主机 API - How to use a localhost API in angular 如何解决角度 PathLocationStrategy(html5 route) 刷新 404 而不将所有资源重定向到主页 - How to solve angular PathLocationStrategy(html5 route) refresh 404 without reidirect all resources to home page PathLocationStrategy仅在本地工作 - PathLocationStrategy works only locally IE9 PathLocationStrategy Angular 4 - IE9 PathLocationStrategy Angular 4 如何在本地主机中使用Cloud Firebase功能使用angular - How to use angular with cloud firebase function in localhost Web应用中的PathLocationStrategy与HashLocationStrategy - PathLocationStrategy vs HashLocationStrategy in web apps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM