找到 service-worker.ngsw.json 文件并将 "baseHref": "/" 修改为你应用程序的实际基本路径。比如,如果你的应用程序部署在了 myapp.com/myapp 路径下,那么应该将 "baseHref": "/myapp/"。
在 angular.json 文件里面找到对应的配置文件(比如 production 或者 staging),添加一个 outputPublicPath 属性,并将其设置为你应用程序的实际基本路径。例如:
"configurations": {
"production": {
"outputPath": "dist/myapp",
"outputPublicPath": "/myapp/",
...
RewriteEngine On
RewriteBase /myapp/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myapp/index.html [L]
以上的步骤可以帮助你解决 Angular PWA 在非根目录下更新时的问题。