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

Commit 4412fe2

Browse files
rrsivabalanpetebacondarwin
authored andcommitted
fix($location): ensure $locationChangeSuccess fires even if URL ends with #
Closes #12175 Closes #13251
1 parent 8088284 commit 4412fe2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ function $LocationProvider() {
918918
var oldUrl = $location.absUrl();
919919
var oldState = $location.$$state;
920920
var defaultPrevented;
921-
921+
newUrl = trimEmptyHash(newUrl);
922922
$location.$$parse(newUrl);
923923
$location.$$state = newState;
924924

test/ng/locationSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,31 @@ describe('$location', function() {
21412141
})
21422142
);
21432143

2144+
it('should fire $locationChangeSuccess when browser location changes to URL which ends with #',
2145+
inject(function($location, $browser, $rootScope, $log) {
2146+
$location.url('/somepath');
2147+
$rootScope.$apply();
2148+
2149+
expect($browser.url()).toEqual('http://server/#/somepath');
2150+
expect($location.url()).toEqual('/somepath');
2151+
2152+
$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
2153+
$log.info('start', newUrl, oldUrl);
2154+
});
2155+
$rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) {
2156+
$log.info('after', newUrl, oldUrl);
2157+
});
2158+
2159+
$browser.url('http://server/#');
2160+
$browser.poll();
2161+
2162+
expect($log.info.logs.shift()).
2163+
toEqual(['start', 'http://server/', 'http://server/#/somepath']);
2164+
expect($log.info.logs.shift()).
2165+
toEqual(['after', 'http://server/', 'http://server/#/somepath']);
2166+
})
2167+
);
2168+
21442169
it('should allow redirect during browser url change',
21452170
inject(function($location, $browser, $rootScope, $log) {
21462171
$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {

0 commit comments

Comments
 (0)