Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS 2 and Cordova: "Failed to load resource: net::ERR_FILE_NOT_FOUND"

I am trying to get an Angular2 app running natively on Android using Cordova. Unfortunately, the app only shows the loading screen of the Angular app but is not able to load the app.

I am getting the following error message:

Failed to load resource: net::ERR_FILE_NOT_FOUND     file:///app/styles.css 
Failed to load resource: net::ERR_FILE_NOT_FOUND     file:///app/libs-bundle.js
Failed to load resource: net::ERR_FILE_NOT_FOUND     file:///app/main.js Failed to load resource: net::ERR_FILE_NOT_FOUND

It seems like all the local resources included in the app cannot be loaded.

like image 662
Paul Avatar asked Sep 18 '16 03:09

Paul


2 Answers

I finally found the problem:

For the routing inside the Angular2 app I defined the <base href="/"> tag in the index.html. This works fine when running the app from a web-server. Though, for Cordova/Phonegap it has to be changed to <base href="file:///android_asset/www/" />.

like image 154
Paul Avatar answered Oct 20 '22 17:10

Paul


<base href="./" /> or <base href="." /> also works, the same approach. Thanks for your commit, it helped me.

like image 30
Gavin Avatar answered Oct 20 '22 16:10

Gavin