Skip to content

Commit

Permalink
fix(urlMatcherFactory): Revert to 0.2.13 behavior where all string pa…
Browse files Browse the repository at this point in the history
…rameters are considered optional

fix(urlRouter): When reloadOnSearch is false, also update the URL.
Fixes #1963
Fixes #1803
Fixes #1079
  • Loading branch information
christopherthielen committed May 19, 2015
1 parent 42095a5 commit 495a02c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -1032,9 +1032,15 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
// that we've initiated ourselves, because we might accidentally abort a legitimate
// transition initiated from code?
if (shouldSkipReload(to, toParams, from, fromParams, locals, options)) {
if (to.self.reloadOnSearch !== false) $urlRouter.update();
if (hash) toParams['#'] = hash;
$state.params = toParams;
copy($state.params, $stateParams);
if (options.location && to.navigable && to.navigable.url) {
$urlRouter.push(to.navigable.url, toParams, {
$$avoidResync: true, replace: options.location === 'replace'
});
$urlRouter.update(true);
}
$state.transition = null;
return $q.when($state.current);
}
Expand Down
7 changes: 3 additions & 4 deletions src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,14 @@ function $UrlMatcherFactory() {

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

var $types = {}, enqueue = true, typeQueue = [], injector, defaultTypes = {
string: {
encode: valToString,
decode: valFromString,
is: function(val) { return typeof val === "string"; },
// TODO: in 1.0, make string .is() return false if value is undefined/null by default.
// In 0.2.x, string params are optional by default for backwards compat
is: function(val) { return val == null || !isDefined(val) || typeof val === "string"; },
pattern: /[^/]*/
},
int: {
Expand Down
13 changes: 13 additions & 0 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ describe('state', function () {
expect(called).toBeFalsy();
}));

it('updates URL when changing only query params via $state.go() when reloadOnSearch=false', inject(function ($state, $stateParams, $q, $location, $rootScope){
initStateTo(RS);
var called;
$state.go(".", { term: 'goodbye' });
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams) {
called = true
});
$q.flush();
expect($stateParams).toEqual({term: 'goodbye'});
expect($location.url()).toEqual("/search?term=goodbye");
expect(called).toBeFalsy();
}));

it('does trigger state change for path params even if reloadOnSearch is false', inject(function ($state, $q, $location, $rootScope){
initStateTo(RSP, { doReload: 'foo' });
expect($state.params.doReload).toEqual('foo');
Expand Down

0 comments on commit 495a02c

Please sign in to comment.