The easiest way is to use
window.location.origin + window.location.pathname
which will return http://example-domain/someApp
This will provide the entire base url, even if you use virtual directories / paths. However, IE does not support the origin. As a result, you could combine the components of the URL to provide you with a base directory as follows:
window.location.protocol + "//" + window.location.hostname + window.location.pathname
which will return http://example-domain/someApp
If you use virtual directories, it will be difficult for you to use $location , since $location.path() returns AFTER the hash, and $location.host() returns only the domain, not the domain and directory, which means window.location.hostname + window.location.pathname .
David l
source share