mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix $location to handle updates to empty hash well
This commit is contained in:
parent
9462c78fbf
commit
c648fee5c2
2 changed files with 22 additions and 3 deletions
|
|
@ -109,7 +109,7 @@ angularServiceInject("$location", function($browser) {
|
|||
extend(location, parseHref(href));
|
||||
} else {
|
||||
if (isDefined(href.hash)) {
|
||||
extend(href, parseHash(href.hash));
|
||||
extend(href, isString(href.hash) ? parseHash(href.hash) : href.hash);
|
||||
}
|
||||
|
||||
extend(location, href);
|
||||
|
|
@ -155,7 +155,9 @@ angularServiceInject("$location", function($browser) {
|
|||
} else
|
||||
hash.hashSearch = path;
|
||||
|
||||
update(hash);
|
||||
hash.hash = composeHash(hash);
|
||||
|
||||
update({hash: hash});
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -187,7 +189,7 @@ angularServiceInject("$location", function($browser) {
|
|||
}
|
||||
if (location.hash != lastLocation.hash) {
|
||||
var hash = parseHash(location.hash);
|
||||
updateHash(hash.path, hash.search);
|
||||
updateHash(hash.hashPath, hash.hashSearch);
|
||||
} else {
|
||||
location.hash = composeHash(location);
|
||||
location.href = composeHref(location);
|
||||
|
|
|
|||
|
|
@ -298,6 +298,12 @@ describe("service", function(){
|
|||
$location.update('http://www.angularjs.org/index.php#');
|
||||
expect($location.href).toEqual('http://www.angularjs.org/index.php');
|
||||
});
|
||||
|
||||
it('should clear hash when updating to hash-less URL', function() {
|
||||
$location.update('http://server');
|
||||
expect($location.href).toBe('http://server');
|
||||
expect($location.hash).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -320,6 +326,17 @@ describe("service", function(){
|
|||
expect($location.hashSearch).toEqual({a: 'b'});
|
||||
expect($location.hashPath).toEqual('path');
|
||||
});
|
||||
|
||||
it('should update href and hash when updating to empty string', function() {
|
||||
$location.updateHash('');
|
||||
expect($location.href).toBe('http://server');
|
||||
expect($location.hash).toBe('');
|
||||
|
||||
scope.$eval();
|
||||
|
||||
expect($location.href).toBe('http://server');
|
||||
expect($location.hash).toBe('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue