@@ -954,7 +954,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
954954 * have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd
955955 * use this when you want to force a reload when *everything* is the same, including search params.
956956 * if String, then will reload the state with the name given in reload, and any children.
957- * if Object, then a stateObj is expected, will reload the state found in stateObj, and any chhildren .
957+ * if Object, then a stateObj is expected, will reload the state found in stateObj, and any children .
958958 *
959959 * @returns {promise } A promise representing the state of the new transition. See
960960 * {@link ui.router.state.$state#methods_go $state.go}.
@@ -1002,7 +1002,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
10021002
10031003 // Starting from the root of the path, keep all levels that haven't changed
10041004 var keep = 0 , state = toPath [ keep ] , locals = root . locals , toLocals = [ ] ;
1005- var skipTriggerReloadCheck = false ;
10061005
10071006 if ( ! options . reload ) {
10081007 while ( state && state === fromPath [ keep ] && state . ownParams . $$equals ( toParams , fromParams ) ) {
@@ -1020,8 +1019,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
10201019 throw new Error ( "No such reload state '" + ( isString ( options . reload ) ? options . reload : options . reload . name ) + "'" ) ;
10211020 }
10221021
1023- skipTriggerReloadCheck = true ;
1024-
10251022 while ( state && state === fromPath [ keep ] && state !== reloadState ) {
10261023 locals = toLocals [ keep ] = state . locals ;
10271024 keep ++ ;
@@ -1034,8 +1031,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
10341031 // TODO: We may not want to bump 'transition' if we're called from a location change
10351032 // that we've initiated ourselves, because we might accidentally abort a legitimate
10361033 // transition initiated from code?
1037- if ( ! skipTriggerReloadCheck && shouldTriggerReload ( to , from , locals , options ) ) {
1034+ if ( shouldSkipReload ( to , toParams , from , fromParams , locals , options ) ) {
10381035 if ( to . self . reloadOnSearch !== false ) $urlRouter . update ( ) ;
1036+ $state . params = toParams ;
1037+ copy ( $state . params , $stateParams ) ;
10391038 $state . transition = null ;
10401039 return $q . when ( $state . current ) ;
10411040 }
@@ -1429,8 +1428,27 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
14291428 return $state ;
14301429 }
14311430
1432- function shouldTriggerReload ( to , from , locals , options ) {
1433- if ( to === from && ( ( locals === from . locals && ! options . reload ) || ( to . self . reloadOnSearch === false ) ) ) {
1431+ function shouldSkipReload ( to , toParams , from , fromParams , locals , options ) {
1432+ // Return true if there are no differences in non-search (path/object) params, false if there are differences
1433+ function nonSearchParamsEqual ( fromAndToState , fromParams , toParams ) {
1434+ // Identify whether all the parameters that differ between `fromParams` and `toParams` were search params.
1435+ function notSearchParam ( key ) {
1436+ return fromAndToState . params [ key ] . location != "search" ;
1437+ }
1438+ var nonQueryParamKeys = fromAndToState . params . $$keys ( ) . filter ( notSearchParam ) ;
1439+ var nonQueryParams = pick . apply ( this , [ fromAndToState . params ] . concat ( nonQueryParamKeys ) ) ;
1440+ var nonQueryParamSet = new $$UMFP . ParamSet ( nonQueryParams ) ;
1441+ return nonQueryParamSet . $$equals ( fromParams , toParams )
1442+ }
1443+
1444+ // If reload was not explicitly requested
1445+ // and we're transitioning to the same state we're already in
1446+ // and the locals didn't change
1447+ // or they changed in a way that doesn't merit reloading
1448+ // (reloadOnParams:false, or reloadOnSearch.false and only search params changed)
1449+ // Then return true.
1450+ if ( ! options . reload && to === from &&
1451+ ( locals === from . locals || ( to . self . reloadOnSearch === false && nonSearchParamsEqual ( from , fromParams , toParams ) ) ) ) {
14341452 return true ;
14351453 }
14361454 }
0 commit comments