@@ -954,7 +954,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
954
954
* have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd
955
955
* use this when you want to force a reload when *everything* is the same, including search params.
956
956
* 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 .
958
958
*
959
959
* @returns {promise } A promise representing the state of the new transition. See
960
960
* {@link ui.router.state.$state#methods_go $state.go}.
@@ -1002,7 +1002,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1002
1002
1003
1003
// Starting from the root of the path, keep all levels that haven't changed
1004
1004
var keep = 0 , state = toPath [ keep ] , locals = root . locals , toLocals = [ ] ;
1005
- var skipTriggerReloadCheck = false ;
1006
1005
1007
1006
if ( ! options . reload ) {
1008
1007
while ( state && state === fromPath [ keep ] && state . ownParams . $$equals ( toParams , fromParams ) ) {
@@ -1020,8 +1019,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1020
1019
throw new Error ( "No such reload state '" + ( isString ( options . reload ) ? options . reload : options . reload . name ) + "'" ) ;
1021
1020
}
1022
1021
1023
- skipTriggerReloadCheck = true ;
1024
-
1025
1022
while ( state && state === fromPath [ keep ] && state !== reloadState ) {
1026
1023
locals = toLocals [ keep ] = state . locals ;
1027
1024
keep ++ ;
@@ -1034,8 +1031,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1034
1031
// TODO: We may not want to bump 'transition' if we're called from a location change
1035
1032
// that we've initiated ourselves, because we might accidentally abort a legitimate
1036
1033
// transition initiated from code?
1037
- if ( ! skipTriggerReloadCheck && shouldTriggerReload ( to , from , locals , options ) ) {
1034
+ if ( shouldSkipReload ( to , toParams , from , fromParams , locals , options ) ) {
1038
1035
if ( to . self . reloadOnSearch !== false ) $urlRouter . update ( ) ;
1036
+ $state . params = toParams ;
1037
+ copy ( $state . params , $stateParams ) ;
1039
1038
$state . transition = null ;
1040
1039
return $q . when ( $state . current ) ;
1041
1040
}
@@ -1429,8 +1428,27 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1429
1428
return $state ;
1430
1429
}
1431
1430
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 ) ) ) ) {
1434
1452
return true ;
1435
1453
}
1436
1454
}
0 commit comments