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

fix($location): path to work with full url #8924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down