Open sitexw opened 5 years ago
Hi, thanks for reporting this.
Can you explain why your Google Cloud Storage bucket is not configured to point to the index.html
?
Most likely setting the baseHref
to a file, will have other repercussions when using lazy loading, css assets if absolute paths are used etc.
@alan-agius4, what other repercussions do you have in mind? Using a file as baseHref is valid. IMO, cli should suport that and treat it the same way as it will be treated in the browser (i.e. ignore the file part if it wants to combine it with a relative path).
@gkalpak, I totally agree!
My point was that when baseHref is a file it is not being set properly not only in service worker, but applies to a lot of other user cases. Such as lazy loading, absolute css resources etc...
So setting the baseHref to a file at the moment will break not only the service worker but other functionality (depending on what functionality you are using).
And I agree that it should be addressed 😀
Bug Report or Feature Request
From here: https://github.com/angular/angular/issues/26917
Command
Versions
Current behavior
I have a problem with the file
ngsw.json
(dist/xxx/ngsw.json
), when I build my application. Here is the configuration of my fileangular.json
:As you can see, my
baseHref
points to a file (index.html
). And when I compile, here is the result of the filengsw.json
:As you can see, it generates all the urls of the file with the
.../index.html/...
, as if it were a folder. As this file is used for the cache of the application, the cache does not work since it is not the right url...Expected behavior
I think the file should have looked like this:
Minimal reproduction of the problem with instructions
You just have to create an application (which uses PWA) and have a baseHref that points to a file (eg:
index.html
). And when you compile your application, the url generated in thengsw.json
file will be wrong.What is the motivation / use case for changing the behavior?
I think it would just take into account when the "baseHref" to deal with a file, take the root of the file (and not take the file for a folder).
For information, I use a
baseHref
to a file, because I use the system of route of Angular with the hash and that the urlhttps://storage.googleapis.com/dev-web-xxxxxx-xxxxxx/
does not point towards my fileindex.html
. As the project is hosted on a Google Cloud Storage, when we update the application (CTRL+F5, ...) with a url of this type...-xxxxxx/#/user/login
, I end up with a 404 error (because the url in...-xxxxxx/
does not point to the fileindex.html
). To solve this problem, I force Angular to keep theindex.html
in the URL (eg:...-xxxxxx/index.html#/user/login
), throughbaseHref
with theindex.html
in it.For now, I make the corrections of the url in the file
ngsw.json
manually, so that the cache of the application works...