@@ -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,39 @@ 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 = [ ] ;
1002
+ var skipTriggerReloadCheck = false ;
978
1003
979
1004
if ( ! options . reload ) {
980
1005
while ( state && state === fromPath [ keep ] && state . ownParams . $$equals ( toParams , fromParams ) ) {
981
1006
locals = toLocals [ keep ] = state . locals ;
982
1007
keep ++ ;
983
1008
state = toPath [ keep ] ;
984
1009
}
1010
+ } else if ( isString ( options . reload ) || isObject ( options . reload ) ) {
1011
+ if ( isObject ( options . reload ) && ! options . reload . name ) {
1012
+ throw new Error ( 'Invalid reload state object' ) ;
1013
+ }
1014
+
1015
+ var reloadState = options . reload === true ? fromPath [ 0 ] : findState ( options . reload ) ;
1016
+ if ( options . reload && ! reloadState ) {
1017
+ throw new Error ( "No such reload state '" + ( isString ( options . reload ) ? options . reload : options . reload . name ) + "'" ) ;
1018
+ }
1019
+
1020
+ skipTriggerReloadCheck = true ;
1021
+
1022
+ while ( state && state === fromPath [ keep ] && state !== reloadState ) {
1023
+ locals = toLocals [ keep ] = state . locals ;
1024
+ keep ++ ;
1025
+ state = toPath [ keep ] ;
1026
+ }
985
1027
}
986
1028
987
1029
// If we're going to the same state and all locals are kept, we've got nothing to do.
988
1030
// But clear 'transition', as we still want to cancel any other pending transitions.
989
1031
// TODO: We may not want to bump 'transition' if we're called from a location change
990
1032
// that we've initiated ourselves, because we might accidentally abort a legitimate
991
1033
// transition initiated from code?
992
- if ( shouldTriggerReload ( to , from , locals , options ) ) {
1034
+ if ( ! skipTriggerReloadCheck && shouldTriggerReload ( to , from , locals , options ) ) {
993
1035
if ( to . self . reloadOnSearch !== false ) $urlRouter . update ( ) ;
994
1036
$state . transition = null ;
995
1037
return $q . when ( $state . current ) ;
0 commit comments