# Class TargetState

Encapsulate the target (destination) state/params/options of a [[Transition]].

This class is frequently used to redirect a transition to a new destination.

See:

- [[HookResult]]
- [[TransitionHookFn]]
- [[TransitionService.onStart]]

To create a `TargetState`, use [[StateService.target]].

This class wraps:

1. an identifier for a state
2. a set of parameters
3. and transition options
4. the registered state object (the [[StateDeclaration]])

Many ng-router APIs such as [[StateService.go]] take a [[StateOrName]] argument which can either be a state object (a [[StateDeclaration]] or [[StateObject]]) or a state name (a string). The `TargetState` class normalizes those options.

A `TargetState` may be valid (the state being targeted exists in the registry) or invalid (the state being targeted is not registered).

- Defined in router/state/target-state.js:32
- Defined in router/state/target-state.js:156

#####
Index

### Constructors

constructor

### Properties

_definition
_identifier
_options
_params
_stateRegistry

### Methods

$state
error
exists
identifier
name
options
params
state
toString
valid
withOptions
withParams
withState
isDef

##
Constructors

### constructor

- new TargetState(_stateRegistry, _identifier, _params, _options): TargetState
- `Internal`

  The TargetState constructor

  Note: Do not construct a `TargetState` manually. To create a `TargetState`, use the [[StateService.target]] factory method.

  #### Parameters

  - _stateRegistry: any

    The StateRegistry to use to look up the _definition

  - _identifier: any

    An identifier for a state. Either a fully-qualified state name, or the object used to define the state.

  - _params: any

    Parameters for the target state

  - _options: any

    Transition options.

  #### Returns TargetState

  - Defined in router/state/target-state.js:47

##
Properties

### _definition

_definition: any

- Defined in router/state/target-state.js:53

### _identifier

_identifier: any

- Defined in router/state/target-state.js:49
- Defined in router/state/target-state.js:50

### _options

_options: any

- Defined in router/state/target-state.js:52

### _params

_params: any

- Defined in router/state/target-state.js:51

### _stateRegistry

_stateRegistry: any

- Defined in router/state/target-state.js:48

##
Methods

### $state

- $state(): any

- The internal state object (if it was found)

  #### Returns any

  - Defined in router/state/target-state.js:71

### error

- error(): string

- If the object is invalid, returns the reason why

  #### Returns string

  - Defined in router/state/target-state.js:91

### exists

- exists(): boolean

- True if the target state was found

  #### Returns boolean

  - Defined in router/state/target-state.js:83

### identifier

- identifier(): any

- The identifier used when creating this TargetState

  #### Returns any

  - Defined in router/state/target-state.js:63

### name

- name(): any

- The name of the state this object targets

  #### Returns any

  - Defined in router/state/target-state.js:59

### options

- options(): any

- The target options

  #### Returns any

  - Defined in router/state/target-state.js:79

### params

- params(): any

- The target parameter values

  #### Returns any

  - Defined in router/state/target-state.js:67

### state

- state(): any

- The internal state declaration (if it was found)

  #### Returns any

  - Defined in router/state/target-state.js:75

### toString

- toString(): string

- #### Returns string

  - Defined in router/state/target-state.js:101

### valid

- valid(): boolean

- True if the object is valid

  #### Returns boolean

  - Defined in router/state/target-state.js:87

### withOptions

- withOptions(options, replace?): TargetState

- Returns a copy of this TargetState, using the specified Transition Options.

  #### Parameters

  - options: any

    the new options to use

  - replace: boolean = false

    When false (default) the new options will be merged with the current options. When true the options will be used instead of the current options.

  #### Returns TargetState

  - Defined in router/state/target-state.js:143

### withParams

- withParams(params, replace?): TargetState

- Returns a copy of this TargetState, using the specified parameter values.

  #### Parameters

  - params: any

    the new parameter values to use

  - replace: boolean = false

    When false (default) the new parameter values will be merged with the current values. When true the parameter values will be used instead of the current values.

  #### Returns TargetState

  - Defined in router/state/target-state.js:125

### withState

- withState(state): TargetState

- Returns a copy of this TargetState which targets a different state. The new TargetState has the same parameter values and transition options.

  #### Parameters

  - state: any

    The new state that should be targeted

  #### Returns TargetState

  - Defined in router/state/target-state.js:110

### `Static` isDef

- isDef(obj): boolean

- Returns true if the object has a state property that might be a state or state name

  #### Parameters

  - obj: any

  #### Returns boolean

  - Defined in router/state/target-state.js:156