From b818cb94fbe1d66933fbb459fc4903e0af5a2f67 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Thu, 12 Mar 2015 12:29:24 +0900 Subject: [PATCH 1/2] add unit test --- test/ng/locationSpec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index bbeef29f88e6..393b5c8ba768 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -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'); + }); }); From 24e7d759513e17079c1295e72eadffb905c6bad6 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Thu, 12 Mar 2015 12:29:47 +0900 Subject: [PATCH 2/2] fix working go back --- src/ng/location.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ng/location.js b/src/ng/location.js index dfe22cd000cd..3da0e49ea9b0 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -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 @@ -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);