Skip to content

Commit 495a02c

Browse files
fix(urlMatcherFactory): Revert to 0.2.13 behavior where all string parameters are considered optional
fix(urlRouter): When reloadOnSearch is false, also update the URL. Fixes #1963 Fixes #1803 Fixes #1079
1 parent 42095a5 commit 495a02c

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Diff for: src/state.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1032,9 +1032,15 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
10321032
// that we've initiated ourselves, because we might accidentally abort a legitimate
10331033
// transition initiated from code?
10341034
if (shouldSkipReload(to, toParams, from, fromParams, locals, options)) {
1035-
if (to.self.reloadOnSearch !== false) $urlRouter.update();
1035+
if (hash) toParams['#'] = hash;
10361036
$state.params = toParams;
10371037
copy($state.params, $stateParams);
1038+
if (options.location && to.navigable && to.navigable.url) {
1039+
$urlRouter.push(to.navigable.url, toParams, {
1040+
$$avoidResync: true, replace: options.location === 'replace'
1041+
});
1042+
$urlRouter.update(true);
1043+
}
10381044
$state.transition = null;
10391045
return $q.when($state.current);
10401046
}

Diff for: src/urlMatcherFactory.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,14 @@ function $UrlMatcherFactory() {
571571

572572
function valToString(val) { return val != null ? val.toString().replace(/\//g, "%2F") : val; }
573573
function valFromString(val) { return val != null ? val.toString().replace(/%2F/g, "/") : val; }
574-
// TODO: in 1.0, make string .is() return false if value is undefined by default.
575-
// function regexpMatches(val) { /*jshint validthis:true */ return isDefined(val) && this.pattern.test(val); }
576-
function regexpMatches(val) { /*jshint validthis:true */ return this.pattern.test(val); }
577574

578575
var $types = {}, enqueue = true, typeQueue = [], injector, defaultTypes = {
579576
string: {
580577
encode: valToString,
581578
decode: valFromString,
582-
is: function(val) { return typeof val === "string"; },
579+
// TODO: in 1.0, make string .is() return false if value is undefined/null by default.
580+
// In 0.2.x, string params are optional by default for backwards compat
581+
is: function(val) { return val == null || !isDefined(val) || typeof val === "string"; },
583582
pattern: /[^/]*/
584583
},
585584
int: {

Diff for: test/stateSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ describe('state', function () {
229229
expect(called).toBeFalsy();
230230
}));
231231

232+
it('updates URL when changing only query params via $state.go() when reloadOnSearch=false', inject(function ($state, $stateParams, $q, $location, $rootScope){
233+
initStateTo(RS);
234+
var called;
235+
$state.go(".", { term: 'goodbye' });
236+
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams) {
237+
called = true
238+
});
239+
$q.flush();
240+
expect($stateParams).toEqual({term: 'goodbye'});
241+
expect($location.url()).toEqual("/search?term=goodbye");
242+
expect(called).toBeFalsy();
243+
}));
244+
232245
it('does trigger state change for path params even if reloadOnSearch is false', inject(function ($state, $q, $location, $rootScope){
233246
initStateTo(RSP, { doReload: 'foo' });
234247
expect($state.params.doReload).toEqual('foo');

0 commit comments

Comments
 (0)