@@ -820,11 +820,33 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
820
820
* });
821
821
* </pre>
822
822
*
823
+ * @param {string=|object= } state - A state name or a state object, which is the root of the resolves to be re-resolved.
824
+ * @example
825
+ * <pre>
826
+ * //assuming app application consists of 3 states: 'contacts', 'contacts.detail', 'contacts.detail.item'
827
+ * //and current state is 'contacts.detail.item'
828
+ * var app angular.module('app', ['ui.router']);
829
+ *
830
+ * app.controller('ctrl', function ($scope, $state) {
831
+ * $scope.reload = function(){
832
+ * //will reload 'contact.detail' and 'contact.detail.item' states
833
+ * $state.reload('contact.detail');
834
+ * }
835
+ * });
836
+ * </pre>
837
+ *
838
+ * `reload()` is just an alias for:
839
+ * <pre>
840
+ * $state.transitionTo($state.current, $stateParams, {
841
+ * reload: true, inherit: false, notify: true
842
+ * });
843
+ * </pre>
844
+
823
845
* @returns {promise } A promise representing the state of the new transition. See
824
846
* {@link ui.router.state.$state#methods_go $state.go}.
825
847
*/
826
- $state . reload = function reload ( ) {
827
- return $state . transitionTo ( $state . current , $stateParams , { reload : true , inherit : false , notify : true } ) ;
848
+ $state . reload = function reload ( state ) {
849
+ return $state . transitionTo ( $state . current , $stateParams , { reload : state || true , inherit : false , notify : true } ) ;
828
850
} ;
829
851
830
852
/**
@@ -928,9 +950,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
928
950
* - **`relative`** - {object=}, When transitioning with relative path (e.g '^'),
929
951
* defines which state to be relative from.
930
952
* - **`notify`** - {boolean=true}, If `true` will broadcast $stateChangeStart and $stateChangeSuccess events.
931
- * - **`reload`** (v0.2.5) - {boolean=false}, If `true` will force transition even if the state or params
953
+ * - **`reload`** (v0.2.5) - {boolean=false|string=|object= }, If `true` will force transition even if the state or params
932
954
* have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd
933
955
* use this when you want to force a reload when *everything* is the same, including search params.
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.
934
958
*
935
959
* @returns {promise } A promise representing the state of the new transition. See
936
960
* {@link ui.router.state.$state#methods_go $state.go}.
@@ -975,21 +999,33 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
975
999
976
1000
// Starting from the root of the path, keep all levels that haven't changed
977
1001
var keep = 0 , state = toPath [ keep ] , locals = root . locals , toLocals = [ ] ;
978
-
1002
+ var skipTriggerReloadCheck = false ;
979
1003
if ( ! options . reload ) {
980
1004
while ( state && state === fromPath [ keep ] && state . ownParams . $$equals ( toParams , fromParams ) ) {
981
1005
locals = toLocals [ keep ] = state . locals ;
982
1006
keep ++ ;
983
1007
state = toPath [ keep ] ;
984
1008
}
1009
+ } else if ( isString ( options . reload ) || isObject ( options . reload ) ) {
1010
+ skipTriggerReloadCheck = true ;
1011
+ var stateName = isString ( options . reload ) ? options . reload : options . reload . name ;
1012
+ if ( ! isDefined ( findState ( stateName ) ) ) {
1013
+ throw new Error ( "No such state '" + stateName + "'" ) ;
1014
+ }
1015
+
1016
+ while ( state && state === fromPath [ keep ] && state . toString ( ) . toLowerCase ( ) !== stateName . toLowerCase ( ) ) {
1017
+ locals = toLocals [ keep ] = state . locals ;
1018
+ keep ++ ;
1019
+ state = toPath [ keep ] ;
1020
+ }
985
1021
}
986
1022
987
1023
// If we're going to the same state and all locals are kept, we've got nothing to do.
988
1024
// But clear 'transition', as we still want to cancel any other pending transitions.
989
1025
// TODO: We may not want to bump 'transition' if we're called from a location change
990
1026
// that we've initiated ourselves, because we might accidentally abort a legitimate
991
1027
// transition initiated from code?
992
- if ( shouldTriggerReload ( to , from , locals , options ) ) {
1028
+ if ( ! skipTriggerReloadCheck && shouldTriggerReload ( to , from , locals , options ) ) {
993
1029
if ( to . self . reloadOnSearch !== false ) $urlRouter . update ( ) ;
994
1030
$state . transition = null ;
995
1031
return $q . when ( $state . current ) ;
0 commit comments