1

I followed exactly this tutorial: https://medium.com/@nacojohn/convert-your-angular-project-to-mobile-app-using-cordova-f0384a7711a6

But i get this error when i crdova build browser

ERROR Error: Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///C:/Users/sven/Projects/expense-calculator/platforms/browser/www/' cannot be created in a document with origin 'null' and URL 'file:///C:/Users/sven/Projects/expense-calculator/platforms/browser/www/index.html'.
Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///C:/Users/sven/Projects/expense-calculator/platforms/browser/www/' cannot be created in a document with origin 'null' and URL 'file:///C:/Users/sven/Projects/expense-calculator/platforms/browser/www/index.html'.
    at BrowserPlatformLocation.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.BrowserPlatformLocation.replaceState (platform-browser.js:613)
    at PathLocationStrategy.push../node_modules/@angular/common/fesm5/common.js.PathLocationStrategy.replaceState (common.js:424)
    at Location.push../node_modules/@angular/common/fesm5/common.js.Location.replaceState (common.js:203)
    at Router.push../node_modules/@angular/router/fesm5/router.js.Router.resetUrlToCurrentUrlTree (router.js:3829)
    at Router.push../node_modules/@angular/router/fesm5/router.js.Router.resetStateAndUrl (router.js:3826)
    at router.js:3810
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:3654)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)
    at BrowserPlatformLocation.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.BrowserPlatformLocation.replaceState (platform-browser.js:613)
    at PathLocationStrategy.push../node_modules/@angular/common/fesm5/common.js.PathLocationStrategy.replaceState (common.js:424)
    at Location.push../node_modules/@angular/common/fesm5/common.js.Location.replaceState (common.js:203)
    at Router.push../node_modules/@angular/router/fesm5/router.js.Router.resetUrlToCurrentUrlTree (router.js:3829)
    at Router.push../node_modules/@angular/router/fesm5/router.js.Router.resetStateAndUrl (router.js:3826)
    at router.js:3810
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:3654)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)
    at resolvePromise (zone.js:814)
    at zone.js:877
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:3645)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)

I figure out that its because i try to run angular local. while angular just work on servers. (but why? its just html and js) So is there any solution for my problem? i just want make the app working inside of the apk file that cordova build.

Budi
  • 678
  • 2
  • 6
  • 27
  • Have you tried https://stackoverflow.com/questions/47805178/ios11-cordova-angular-4-wrap-breaking-securityerror-history-replacestate –  Jun 26 '18 at 22:35
  • Yeah, i found this stackoverflow to before i write this post. but this dont work for me. – Budi Jun 26 '18 at 22:40

1 Answers1

0

This is an issue that you are not able to access your SPA resources via file:/// protocol.

In the tutorial, they explicitly mentioned that

Update the <base href=“/”> tag in your index.html to <base href=“./”>, this will enable angular to access files in a directory path since we are not hosting on a server.

deepansh2323
  • 261
  • 1
  • 8