Angular 6 ServiceWorker - index.html 返回响应 404 Not Found [英] Angular 6 ServiceWorker - index.html returned response 404 Not Found
问题描述
我已经在我的测试服务器上部署了 PWA https://www.mytestserver.me/dev/pwa/ 在dev/pwa"文件夹下.该应用程序以 100% 的 PWA 分数通过了 Lighthouse.但是该应用程序仍然无法按预期运行.它根本不起作用.)) JS 控制台说:
I've deployed PWA on my test server https://wwww.mytestserver.me/dev/pwa/ under 'dev/pwa' folder. The app passed Lighthouse with 100% PWA score. But the app still doesn't work as it's expected. It just doesn't work at all. )) JS console says:
无法加载'https://www.mytestserver.me/dev/pwa'.服务工作者向 FetchEvent.respondWith() 传递了一个被拒绝的承诺'错误:响应不正确(fetchAndCacheOnce):请求https://www.mytestserver.me/index.html 返回响应 404 不找到'-ngsw-worker.js:589:31
Failed to load ‘https://wwww.mytestserver.me/dev/pwa’. A ServiceWorker passed a promise to FetchEvent.respondWith() that rejected with ‘Error: Response not Ok (fetchAndCacheOnce): request for https://wwww.mytestserver.me/index.html returned response 404 Not Found’ - ngsw-worker.js:589:31
在我的 manifest.json 中,我有:scope":/"和start_url":/".我试图将它们设置为 https://www.mytestserver.me/dev/pwa/ 和只是/dev/pwa/但结果是一样的.
In my manifest.json I have: "scope": "/" and "start_url": "/". I tried to set them to https://wwww.mytestserver.me/dev/pwa/ and to just /dev/pwa/ but result is the same.
推荐答案
您只需要更改 ngsw-config.json 中的 index 属性从 /index.html 到 /dev/pwa/index.html.
You just need to change index property in your ngsw-config.json from /index.html to /dev/pwa/index.html.
如果这不起作用,您需要清理浏览器缓存.至于我,它只有在完全清除浏览器数据后才开始工作.
If this doesn't work, you need to clean browser caches. As for me it started to work only after complete clearing of browser data.
这篇关于Angular 6 ServiceWorker - index.html 返回响应 404 Not Found的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!