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

Commit

Permalink
fix($location): ensure $locationChangeSuccess fires even if URL end…
Browse files Browse the repository at this point in the history
…s with `#`

Closes #12175
Closes #13251
  • Loading branch information
rrsivabalan authored and petebacondarwin committed Nov 12, 2015
1 parent 34590e1 commit 6f8ddb6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ function $LocationProvider() {
var oldUrl = $location.absUrl();
var oldState = $location.$$state;
var defaultPrevented;

newUrl = trimEmptyHash(newUrl);
$location.$$parse(newUrl);
$location.$$state = newState;

Expand Down
25 changes: 25 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,31 @@ describe('$location', function() {
})
);

it('should fire $locationChangeSuccess when browser location changes to URL which ends with #',
inject(function($location, $browser, $rootScope, $log) {
$location.url('/somepath');
$rootScope.$apply();

expect($browser.url()).toEqual('http://server/#/somepath');
expect($location.url()).toEqual('/somepath');

$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
$log.info('start', newUrl, oldUrl);
});
$rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) {
$log.info('after', newUrl, oldUrl);
});

$browser.url('http://server/#');
$browser.poll();

expect($log.info.logs.shift()).
toEqual(['start', 'http://server/', 'http://server/#/somepath']);
expect($log.info.logs.shift()).
toEqual(['after', 'http://server/', 'http://server/#/somepath']);
})
);

it('should allow redirect during browser url change',
inject(function($location, $browser, $rootScope, $log) {
$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
Expand Down

0 comments on commit 6f8ddb6

Please sign in to comment.