angular: Error when switching different apps with base-href (i18n language switching) (due to service worker)
🐞 bug report
Facing an issue when switching to another app with base-href. I’m using angular i18n and i have 2 languages. i have build it successfully and hosted it with different base-href /de and /en. When i try switching language it throws error due to service worker issue.
Affected Package
The issue is caused by package @angular/service-worker
Is this a regression?
Don't know whether it is worked on previous versionDescription
Facing an issue when switching to another app with base-href. I’m using angular i18n and i have 2 languages. i have build it successfully and hosted it with different base-href /de and /en. When i try to switch the language for first time it is ok because service worker not cached my app.
Note: Below error happens randomly.
Once it cached then i try to switch the language by clicking the de language button and browser starts loading it throws an error (currently I’m in en) Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'de'. Then i got a prompt that update is available (service worker found an update), but no update is published.
Some of the thing i noticed that service worker for both the language is running (maybe the serivce worker depends on domain instead of base-href). Because of this service workers cross checking for update and it shows update
🔬 Minimal Reproduction
create an angular app and intergrate i18n (Not necessary but i followed in my project) add PWA in your app build atleast two languages with different base-href host them in same domain try to switch langauage some times the errors
🔥 Exception or Error
ERROR Error: "Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'de'
ZYCi/gt
🌍 Environment
Angular Version:
Angular CLI: 7.0.3
Node: 10.10.0
OS: win32 x64
Angular: 7.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.10.1
@angular-devkit/build-angular 0.10.1
@angular-devkit/build-optimizer 0.10.1
@angular-devkit/build-webpack 0.10.1
@angular-devkit/core 7.0.1
@angular-devkit/schematics 7.0.3
@angular/cli 7.0.3
@angular/fire 5.1.0
@angular/pwa 0.10.1
@ngtools/webpack 7.0.1
@schematics/angular 7.0.1
@schematics/update 0.10.3
rxjs 6.3.3
typescript 3.1.5
webpack 4.19.1
Anything else relevant?
This issue occurs frequently in Firefox and randomly in chrome.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (16 by maintainers)
@sheikalthaf, glad that you got it working (and even more glad that you are interested in working on a PR \o/). The ServiceWorker does indeed execute in a different context, so it doesn’t have access to DOM. You can use the
registration.scopeto get access to the ServiceWorker’s scope (which is essentially the range of URLs it controls). E.g.:Thx, I will take a look.