Skip to content

Commit 95b16bf

Browse files
committed
Merge pull request #612 from sourcegraph/hash
Preserve url fragment on page reload
2 parents ae360fc + ecf10f0 commit 95b16bf

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/state.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
181181
if (!state['abstract'] && state.url) {
182182
$urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
183183
if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
184-
$state.transitionTo(state, $match, false);
184+
$state.transitionTo(state, $match, { location: false });
185185
}
186186
}]);
187187
}

test/stateSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,17 @@ describe('state', function () {
689689
expect($state.current.name).toBe('about.person');
690690
}));
691691

692+
it('preserve hash', inject(function($state, $rootScope, $location) {
693+
$location.path("/about/bob");
694+
$location.hash("frag");
695+
$rootScope.$broadcast("$locationChangeSuccess");
696+
$rootScope.$apply();
697+
expect($state.params).toEqual({ person: "bob" });
698+
expect($state.current.name).toBe('about.person');
699+
expect($location.path()).toBe('/about/bob');
700+
expect($location.hash()).toBe('frag');
701+
}));
702+
692703
it('should correctly handle absolute urls', inject(function ($state, $rootScope, $location) {
693704
$location.path("/first/subpath");
694705
$rootScope.$broadcast("$locationChangeSuccess");

0 commit comments

Comments
 (0)