Skip to content

Commit 350d3e8

Browse files
fix(reloadOnSearch): Update locals.globals.$stateParams when reloadOnSearch=false
Closes #2356
1 parent 02e9866 commit 350d3e8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/state.js

+1
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
10361036
if (hash) toParams['#'] = hash;
10371037
$state.params = toParams;
10381038
copy($state.params, $stateParams);
1039+
copy(filterByKeys(to.params.$$keys(), $stateParams), to.locals.globals.$stateParams);
10391040
if (options.location && to.navigable && to.navigable.url) {
10401041
$urlRouter.push(to.navigable.url, toParams, {
10411042
$$avoidResync: true, replace: options.location === 'replace'

test/stateSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,28 @@ describe('state', function () {
246246
expect(called).toBeFalsy();
247247
}));
248248

249+
// Test for issue #2356
250+
it('retains reloadOnSearch (dynamic) parameters after going to child, then back to reloadOnSearch state', inject(function ($state, $q, $stateParams, $location, $rootScope){
251+
stateProvider.state('RS.child', { url: "/child", template: 'woo' });
252+
initStateTo(RS);
253+
254+
var called;
255+
$rootScope.$on('$stateChangeStart', function () { called = true });
256+
$state.go(".", { term: 'goodbye' }); $q.flush();
257+
expect($stateParams).toEqual({term: 'goodbye'});
258+
expect($location.url()).toEqual("/search?term=goodbye");
259+
expect(called).toBeFalsy();
260+
261+
$state.go("RS.child"); $q.flush();
262+
expect($stateParams).toEqual({term: 'goodbye'});
263+
expect($location.url()).toEqual("/search/child?term=goodbye");
264+
expect(called).toBeTruthy();
265+
266+
$state.go("RS"); $q.flush();
267+
expect($stateParams).toEqual({term: 'goodbye'});
268+
expect($location.url()).toEqual("/search?term=goodbye");
269+
}));
270+
249271
it('does trigger state change for path params even if reloadOnSearch is false', inject(function ($state, $q, $location, $rootScope){
250272
initStateTo(RSP, { doReload: 'foo' });
251273
expect($state.params.doReload).toEqual('foo');

0 commit comments

Comments
 (0)