简体   繁体   English

Angular 5 PWA未在离线模式下加载

[英]Angular 5 PWA not loading in Offline mode

I have created freshly a PWA with Angular CLI using the following versions: 我使用以下版本使用Angular CLI创建了一个新的PWA:
Angular CLI: 1.6.8 Angular CLI:1.6.8
Node: 8.8.1 节点:8.8.1
Angular: 5.2.5 Angular:5.2.5

My problem: When I go offline I just get a blank page. 我的问题:当我离线时,我只是得到一个空白页面。 The service worker does not load any assets from the cache. 服务工作者不从缓存加载任何资产。 If I manually stop and start it then it will start to work for a short time. 如果我手动停止并启动它,它将开始工作一小段时间。

Haven't changed anything this is what the cli generated. 没有改变任何东西,这是cli产生的。

Configuration I am using: 我正在使用的配置:
ngsw.json: ngsw.json:

{ 
  "index": "/index.html", 
  "assetGroups": [{ 
    "name": "app", 
    "installMode": "prefetch", 
    "resources": { 
      "files": [ "/favicon.ico", "/index.html" ], 
      "versionedFiles": [ "/*.bundle.css", "/*.bundle.js", "/*.chunk.js" ] 
    } 
  }, { 
    "name": "assets", 
    "installMode": "lazy", 
    "updateMode": "prefetch", 
    "resources": { "files": [ "/assets/**" ] } 
  }] 
}

and app.module.ts: 和app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { ServiceWorkerModule } from '@angular/service-worker';
import { AppComponent } from './app.component';

import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Any suggestion where I could start to look for a solution? 有什么建议我可以开始寻找解决方案吗?

If you wish your app to work in offline without index document mentioned (and for all other routes), you have to set up router redirection. 如果您希望您的应用程序在没有提到索引文档的情况下脱机工作(以及所有其他路由),则必须设置路由器重定向。

You can take a look at this SO answer: @angular/service-worker not working when offline 您可以看一下这个SO答案: @ angular / service-worker离线时无法正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM