From ecf10f0c3a89310ca78d4897fe422d97c07a3a65 Mon Sep 17 00:00:00 2001 From: Beyang Liu Date: Thu, 5 Dec 2013 10:59:13 -0800 Subject: [PATCH] fix(registerState): make registerState() use current version of transitionTo() fix hash-overwriting issue on new page load / page reload --- src/state.js | 2 +- test/stateSpec.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/state.js b/src/state.js index ce7f49f43..3a2bf95d2 100644 --- a/src/state.js +++ b/src/state.js @@ -181,7 +181,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $ if (!state['abstract'] && state.url) { $urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) { if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) { - $state.transitionTo(state, $match, false); + $state.transitionTo(state, $match, { location: false }); } }]); } diff --git a/test/stateSpec.js b/test/stateSpec.js index 201a8c969..d52a36fca 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -689,6 +689,17 @@ describe('state', function () { expect($state.current.name).toBe('about.person'); })); + it('preserve hash', inject(function($state, $rootScope, $location) { + $location.path("/about/bob"); + $location.hash("frag"); + $rootScope.$broadcast("$locationChangeSuccess"); + $rootScope.$apply(); + expect($state.params).toEqual({ person: "bob" }); + expect($state.current.name).toBe('about.person'); + expect($location.path()).toBe('/about/bob'); + expect($location.hash()).toBe('frag'); + })); + it('should correctly handle absolute urls', inject(function ($state, $rootScope, $location) { $location.path("/first/subpath"); $rootScope.$broadcast("$locationChangeSuccess");