diff options
| -rw-r--r-- | src/ng/location.js | 8 | ||||
| -rw-r--r-- | test/ng/locationSpec.js | 64 |
2 files changed, 67 insertions, 5 deletions
diff --git a/src/ng/location.js b/src/ng/location.js index 1a7f4208..4c31d0ad 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -128,7 +128,7 @@ function LocationHtml5Url(appBase, basePrefix) { } else { return appBase + prevAppUrl; } - } else if ( (appUrl = beginsWith(appBaseNoFile, url)) ) { + } else if ( (appUrl = beginsWith(appBaseNoFile, url)) !== undefined ) { return appBaseNoFile + appUrl; } else if (appBaseNoFile == url + '/') { return appBaseNoFile; @@ -524,12 +524,12 @@ function $LocationProvider(){ if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return; } - var absHref = elm.prop('href'), - rewrittenUrl = $location.$$rewrite(absHref); + var absHref = elm.prop('href'); + var rewrittenUrl = $location.$$rewrite(absHref); if (absHref && !elm.attr('target') && rewrittenUrl) { event.preventDefault(); - if (rewrittenUrl != initialUrl) { + if (rewrittenUrl != $browser.url()) { // update location manually $location.$$parse(rewrittenUrl); $rootScope.$apply(); diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 3588150d..cf7ceaf4 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -826,7 +826,15 @@ describe('$location', function() { initLocation(), function($browser) { browserTrigger(link, 'click'); - expectNoRewrite($browser, 'http://host.com/base/'); + expectRewriteTo($browser, 'http://host.com/base/'); + + jqLite(link).attr('href', 'http://host.com/base/foo'); + browserTrigger(link, 'click'); + expectRewriteTo($browser, 'http://host.com/base/foo'); + + jqLite(link).attr('href', 'http://host.com/base/'); + browserTrigger(link, 'click'); + expectRewriteTo($browser, 'http://host.com/base/'); } ); }); @@ -1332,4 +1340,58 @@ describe('$location', function() { }); }); }); + + describe('LocationHtml5Url', function() { + var location, locationIndex; + + beforeEach(function() { + location = new LocationHtml5Url('http://server/pre/', 'http://server/pre/path'); + locationIndex = new LocationHtml5Url('http://server/pre/index.html', 'http://server/pre/path'); + }); + + it('should rewrite URL', function() { + expect(location.$$rewrite('http://other')).toEqual(undefined); + expect(location.$$rewrite('http://server/pre')).toEqual('http://server/pre/'); + expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/'); + expect(location.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/otherPath'); + expect(locationIndex.$$rewrite('http://server/pre')).toEqual('http://server/pre/'); + expect(locationIndex.$$rewrite('http://server/pre/')).toEqual('http://server/pre/'); + expect(locationIndex.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/otherPath'); + }); + }); + + + describe('LocationHashbangUrl', function() { + var location; + + beforeEach(function() { + location = new LocationHashbangUrl('http://server/pre/', 'http://server/pre/#/path'); + }); + + it('should rewrite URL', function() { + expect(location.$$rewrite('http://other')).toEqual(undefined); + expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/'); + expect(location.$$rewrite('http://server/pre/#otherPath')).toEqual('http://server/pre/#otherPath'); + }); + }); + + + describe('LocationHashbangInHtml5Url', function() { + var location, locationIndex; + + beforeEach(function() { + location = new LocationHashbangInHtml5Url('http://server/pre/', '#!'); + locationIndex = new LocationHashbangInHtml5Url('http://server/pre/index.html', '#!'); + }); + + it('should rewrite URL', function() { + expect(location.$$rewrite('http://other')).toEqual(undefined); + expect(location.$$rewrite('http://server/pre')).toEqual('http://server/pre/'); + expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/'); + expect(location.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/#!otherPath'); + expect(locationIndex.$$rewrite('http://server/pre')).toEqual('http://server/pre/'); + expect(locationIndex.$$rewrite('http://server/pre/')).toEqual(undefined); + expect(locationIndex.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/index.html#!otherPath'); + }); + }); }); |
