diff --git a/src/ng/location.js b/src/ng/location.js index ab71f7f1d710..cd300d3e905a 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -415,10 +415,19 @@ LocationHashbangInHtml5Url.prototype = * @param {(string|number)=} path New path * @return {string} path */ - path: locationGetterSetter('$$path', function(path) { - path = path ? path.toString() : ''; - return path.charAt(0) == '/' ? path : '/' + path; - }), + path: function(newPath) { + if (isUndefined(newPath)) + return this['$$path']; + var index = newPath.indexOf(this.appBase); + if ( index >= 0 ) { + this.$$parse(newPath); + return this; + } + newPath = newPath ? newPath.toString() : ''; + this['$$path'] = newPath.charAt(0) == '/' ? newPath : '/' + newPath; + this.$$compose(); + return this; + }, /** * @ngdoc method diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index f987cd84c852..18ffce5022ba 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -652,6 +652,16 @@ describe('$location', function() { expect($browser.url()).toBe('http://new.com/a/b#!/new/path'); })); + it('should update browser when $location path is set using full url', inject(function($rootScope, $browser, $location) { + var $browserUrl = spyOnlyCallsWithArgs($browser, 'url').andCallThrough(); + $location.path('http://new.com/a/b#!/new/path'); + expect($browserUrl).not.toHaveBeenCalled(); + $rootScope.$apply(); + + expect($browserUrl).toHaveBeenCalledOnce(); + expect($browser.url()).toBe('http://new.com/a/b#!/new/path'); + expect($location.path()).toBe('/new/path'); + })); it('should update browser only once per $apply cycle', inject(function($rootScope, $browser, $location) { var $browserUrl = spyOnlyCallsWithArgs($browser, 'url').andCallThrough();