@@ -135,7 +135,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
135135 if ( state && ( isStr || ( ! isStr && ( state === stateOrName || state . self === stateOrName ) ) ) ) {
136136 return state ;
137137 }
138- throw new Error ( isStr ? "No such state '" + name + "'" : "Invalid or unregistered state" ) ;
138+ return undefined ;
139139 }
140140
141141
@@ -213,9 +213,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
213213 if ( ! isDefined ( options ) ) options = ( options === true || options === false ) ? { location : options } : { } ;
214214 options = extend ( { location : true , inherit : false , relative : null } , options ) ;
215215
216- to = findState ( to , options . relative ) ;
217- if ( to [ 'abstract' ] ) throw new Error ( "Cannot transition to abstract state '" + to + "'" ) ;
218- if ( options . inherit ) toParams = inheritParams ( $stateParams , toParams || { } , $state . $current , to ) ;
216+ var toState = findState ( to , options . relative ) ;
217+ if ( ! isDefined ( toState ) ) throw new Error ( "No such state " + toState ) ;
218+ if ( toState [ 'abstract' ] ) throw new Error ( "Cannot transition to abstract state '" + to + "'" ) ;
219+ if ( options . inherit ) toParams = inheritParams ( $stateParams , toParams || { } , $state . $current , toState ) ;
220+ to = toState ;
219221
220222 var toPath = to . path ,
221223 from = $state . $current , fromParams = $state . params , fromPath = from . path ;
@@ -313,16 +315,19 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
313315 } ;
314316
315317 $state . is = function is ( stateOrName ) {
316- return $state . $current === findState ( stateOrName ) ;
318+ var state = findState ( stateOrName ) ;
319+ return ( isDefined ( state ) ) ? $state . $current === state : undefined ;
317320 } ;
318321
319322 $state . includes = function includes ( stateOrName ) {
320- return $state . $current . includes [ findState ( stateOrName ) . name ] ;
323+ var state = findState ( stateOrName ) ;
324+ return ( isDefined ( state ) ) ? isDefined ( $state . $current . includes [ state . name ] ) : undefined ;
321325 } ;
322326
323327 $state . href = function href ( stateOrName , params , options ) {
324328 options = extend ( { lossy : true , inherit : false , relative : $state . $current } , options || { } ) ;
325329 var state = findState ( stateOrName , options . relative ) ;
330+ if ( ! isDefined ( state ) ) return null ;
326331
327332 params = inheritParams ( $stateParams , params || { } , $state . $current , state ) ;
328333 var nav = ( state && options . lossy ) ? state . navigable : state ;
@@ -332,7 +337,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
332337
333338 $state . getConfig = function ( stateOrName ) {
334339 var state = findState ( stateOrName ) ;
335- return state . self || null ;
340+ return ( state && state . self ) ? state . self : null ;
336341 } ;
337342
338343 function resolveState ( state , params , paramsAreFiltered , inherited , dst ) {
0 commit comments