[SOLVED] Assets http get 404 only on devices


#1

Out of nowhere or after having refreshed all my libs (still use Angular v5) I get the following error on devices (both iOS and Android) while trying to load assets

{“headers”:{“normalizedNames”:{},“lazyUpdate”:null},“status”:404,“statusText”:“Not Found”,“url”:“http://localhost:8080/assets/nothing.json",“ok”:false,“name”:“HttpErrorResponse”,“message”:"Http failure response for http://localhost:8080/assets/something.json: 404 Not Found”,“error”:null}

the code

this.httpClient.get('./assets/something.json')
                .subscribe((res: any) => {
                  ....

My app is productive since a while, pushed many updates in store etc. code is the same and with ionic serve I can’t reproduce the problem

Double checked, assets files are correctly copied in the platform (which I didn’t removed and added, still the same as my successful delivery in both App store and Google Play)

Any idea where I should began to search the problem?


#2

WHAAATTTT?!!?!??!!?

ok I found the root of the problem: in order to remove the hashbang # in the urls for my PWA I have set locationStrategy to 'path' in app.modules.ts

 IonicModule.forRoot(MyApp, {
   ...
   locationStrategy: 'path'
 }

which actually block or break, as you want, all http.get to the local assets on both devices iOS and Android

removing the strategy fix the issue. I guess this gonna be one of a few things which will be different on PWA or Cordova…looking forward to v4 router to solve that :wink: