Search code examples
angularangular-routingangular-service-worker

Angular Service Worker issue when opening App page in new Tab


Angular 7 app with service-worker re-direct to a new tab and a new page on the same application does not work. I have a link that I email users which once clicked, would send the user to www.mysite.com/mymessages. After I have enabled the service worker, the link does not work. I have been changing the service-worker configuration, including and excluding urls but no success.

A quick test just created a new app with a PROJECT components. Its runs on localhost:8000, built with production flags.

  -works

    this.router.navigate(['/projects']); 

  -open in new Tab does not work

    window.open('localhost:8000/projects', "_blank");  

There must be something easy that I am missing, I should be able to get to a page on my app on a new TAB.

Changing the service worker configuration doesn't seem to do anything.

Service Worker configuration:

 "index": "/index.html",
  "version" : 1.3,
  "dataGroups": [{
    "name": "api-freshness",
    "urls": [
      "!/**/mymessages"
    ],
    "version" : 1,
    "cacheConfig": {
      "strategy": "freshness",
      "maxSize": 100,
      "maxAge": "3d",
      "timeout": "10s"
    }
  }

Should be able to open new page in new Tab, but just isn't working for me.

UPDATE - removing localhost:8000 from window.open will work for my test example. But the main issue remain ... being able to go to a specific page on my site by clicking on a URL link in an email.


Solution

  • Just try this

    window.open('/projects', "_blank");