Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($location): LocationHashbangUrl() undefined error #11302

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function LocationHashbangUrl(appBase, hashPrefix) {
var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
var withoutHashUrl;

if (withoutBaseUrl.charAt(0) === '#') {
if (!isUndefined(withoutBaseUrl) && withoutBaseUrl.charAt(0) === '#') {

// The rest of the url starts with a hash so we have
// got either a hashbang path or a plain hash fragment
Expand All @@ -199,7 +199,15 @@ function LocationHashbangUrl(appBase, hashPrefix) {
// There was no hashbang path nor hash fragment:
// If we are in HTML5 mode we use what is left as the path;
// Otherwise we ignore what is left
withoutHashUrl = this.$$html5 ? withoutBaseUrl : '';
if (this.$$html5) {
withoutHashUrl = withoutBaseUrl;
} else {
withoutHashUrl = '';
if (isUndefined(withoutBaseUrl)) {
appBase = url;
this.replace();
}
}
}

parseAppUrl(withoutHashUrl, this);
Expand Down
8 changes: 8 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,14 @@ describe('$location', function() {
it('should throw on url(urlString, stateObject)', function() {
throwOnState(location);
});

it('should rewrite different base URL', function() {
location = new LocationHashbangUrl('http://server/pre/index.html', '#');

location.$$parse('http://server/next/index.html');
expect(location.url()).toBe('');
expect(location.absUrl()).toBe('http://server/next/index.html');
});
});


Expand Down