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

fix($location): $locationchangesuccess not fires when browser location changes to URL which ends with# issue #12175 #13251

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 3 additions & 3 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,16 +918,16 @@ function $LocationProvider() {
var oldUrl = $location.absUrl();
var oldState = $location.$$state;
var defaultPrevented;

var trimNewUrl = trimEmptyHash(newUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces for tabs

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

defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl,
defaultPrevented = $rootScope.$broadcast('$locationChangeStart', trimNewUrl, oldUrl,
newState, oldState).defaultPrevented;

// if the location was changed by a `$locationChangeStart` handler then stop
// processing this location change
if ($location.absUrl() !== newUrl) return;
if ($location.absUrl() !== trimNewUrl) return;

if (defaultPrevented) {
$location.$$parse(oldUrl);
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