@@ -135,7 +135,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
135
135
if ( state && ( isStr || ( ! isStr && ( state === stateOrName || state . self === stateOrName ) ) ) ) {
136
136
return state ;
137
137
}
138
- throw new Error ( isStr ? "No such state '" + name + "'" : "Invalid or unregistered state" ) ;
138
+ return undefined ;
139
139
}
140
140
141
141
@@ -213,9 +213,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
213
213
if ( ! isDefined ( options ) ) options = ( options === true || options === false ) ? { location : options } : { } ;
214
214
options = extend ( { location : true , inherit : false , relative : null } , options ) ;
215
215
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 ;
219
221
220
222
var toPath = to . path ,
221
223
from = $state . $current , fromParams = $state . params , fromPath = from . path ;
@@ -313,16 +315,19 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
313
315
} ;
314
316
315
317
$state . is = function is ( stateOrName ) {
316
- return $state . $current === findState ( stateOrName ) ;
318
+ var state = findState ( stateOrName ) ;
319
+ return ( isDefined ( state ) ) ? $state . $current === state : undefined ;
317
320
} ;
318
321
319
322
$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 ;
321
325
} ;
322
326
323
327
$state . href = function href ( stateOrName , params , options ) {
324
328
options = extend ( { lossy : true , inherit : false , relative : $state . $current } , options || { } ) ;
325
329
var state = findState ( stateOrName , options . relative ) ;
330
+ if ( ! isDefined ( state ) ) return null ;
326
331
327
332
params = inheritParams ( $stateParams , params || { } , $state . $current , state ) ;
328
333
var nav = ( state && options . lossy ) ? state . navigable : state ;
@@ -332,7 +337,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
332
337
333
338
$state . getConfig = function ( stateOrName ) {
334
339
var state = findState ( stateOrName ) ;
335
- return state . self || null ;
340
+ return ( state && state . self ) ? state . self : null ;
336
341
} ;
337
342
338
343
function resolveState ( state , params , paramsAreFiltered , inherited , dst ) {
0 commit comments