Cordova/PhoneGap base URL

Cordova apps have a different base URL depending on the platform, so short of specifying a different environment for every platform, you can’t really set a base URL. I’ve found that a simple workaround is to switch location from auto to hash in production. I’m not sure this is the best approach, though; at the very least, it breaks Ember Simple Auth’s behavior to force a page refresh after logout by replacing the window location with the base URL.

  1. Is there a better approach currently than using hash-style URLs?

  2. Why can’t Ember simply look at window.location.href on boot to automatically determine the base URL?


I’ve found the location object in cordova/phonegap to be inconsistent and buggy. For refreshing Phonegap in a logout situation, I’ve found this to work consistently.

window.location.href = window.location.toString().substr(0, window.location.toString().indexOf('#'));

In regards to your other issue, I haven’t encountered that as a problem on Android or iOS, you really don’t need to know about the base URL (outside of refresh). I use grunt-phonegap to keep assets separate from phonegap and to be able to use ember-cli still, and I built / been working on to enable gapreload.

I use a very similar code for refreshing. Thanks for the other tips! It would be nice if CLI worked with PhoneGap out of the box, though. I just found this issue where it sounds like it’s been hashed out a bit already, though.