---
url: https://lit-ui-router.dev/reference/lit-ui-router-mobx/classes/RouterStore.md
---
[lit-ui-router-mobx](../index.md) / RouterStore

# Class: RouterStore

Defined in: ui-router-mobx/dist/router-store.d.ts:18

An observable mirror of a router's current state.

A single `transitionService.onSuccess` hook (registered by
[attach](#attach)) pushes the current state, params, and
transition into MobX observables. Any MobX `reaction`, `autorun` or
`computed` that reads the store re-runs when the values it reads change,
with no per-consumer transition hooks. An `onStart` hook feeds the two
fields about the newest transition, [pending](#pending)
and [error](#error).

Use the [for](#for) factory to get the store for a
router: it memoizes one store (and its transition hooks) per router
instance.

## Constructors

### Constructor

```ts
new RouterStore(): RouterStore;
```

Defined in: ui-router-mobx/dist/router-store.d.ts:49

#### Returns

`RouterStore`

## Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
|  `current?` | [`StateDeclaration`](https://ui-router.github.io/core/docs/latest/interfaces/_state_interface_.statedeclaration.html) | The current state declaration (`globals.current`). | ui-router-mobx/dist/router-store.d.ts:20 |
|  `error?` | `Rejection` | The newest transition's failure, as core's `Rejection`: set only for a `RejectType.ERROR` rejection, such as a throwing resolve, and cleared when the next transition starts. Superseded, redirected, aborted and ignored transitions leave it `undefined`, as does a success. One action writes it with [pending](#pending), so a failure changes both together. | ui-router-mobx/dist/router-store.d.ts:39 |
|  `params` | [`RawParams`](https://ui-router.github.io/core/docs/latest/interfaces/_params_interface_.rawparams.html) | The current parameter values (`globals.params`), replaced per transition. | ui-router-mobx/dist/router-store.d.ts:22 |
|  `pending?` | [`Transition`](https://ui-router.github.io/core/docs/latest/classes/_transition_transition_.transition.html) | The newest transition still in flight; `undefined` when none is. A superseded transition never clears its successor, and an error or abort clears it like a success does. | ui-router-mobx/dist/router-store.d.ts:30 |
|  `transition?` | [`Transition`](https://ui-router.github.io/core/docs/latest/classes/_transition_transition_.transition.html) | The most recent successful transition. | ui-router-mobx/dist/router-store.d.ts:24 |

## Methods

### attach()

```ts
attach(router): () => void;
```

Defined in: ui-router-mobx/dist/router-store.d.ts:65

Starts mirroring the given router. Called by
[for](#for); call directly only when managing the
store instance yourself.

Idempotent per router: attaching again to the router already being
mirrored returns the same deregistration function instead of
registering the hooks again. Calling that function detaches the store,
after which it can be attached again.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `router` | [`UIRouter`](https://ui-router.github.io/core/docs/latest/classes/_router_.uirouter.html) |

#### Returns

the hooks' deregistration function.

() => `void`

#### Throws

if the store is already attached to a *different* router — one
store mirrors one router; use [for](#for) to get that
router's own store.

***

### for()

```ts
static for(router): RouterStore;
```

Defined in: ui-router-mobx/dist/router-store.d.ts:48

The observable store for the given router — one per router instance.
The first call attaches the store's transition hooks; the hooks (and
the store) live as long as the router itself.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `router` | [`UIRouter`](https://ui-router.github.io/core/docs/latest/classes/_router_.uirouter.html) |

#### Returns

`RouterStore`

***

### includes()

#### Call Signature

```ts
includes<N>(state, params?): this is never;
```

Defined in: ui-router-mobx/dist/router-store.d.ts:73

Observable version of `StateService.includes`: is the state (or glob
pattern, e.g. `'admin.**'`) included in the current active state? A
state name `RouteTypes` registers narrows `current` and `params`.

##### Type Parameters

| Type Parameter |
| ------ |
|  `N` *extends* `never` |

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `state` | `N` |
| `params?` | [`RawParams`](https://ui-router.github.io/core/docs/latest/interfaces/_params_interface_.rawparams.html) |

##### Returns

`this is never`

#### Call Signature

```ts
includes(stateOrName, params?): boolean;
```

Defined in: ui-router-mobx/dist/router-store.d.ts:74

Observable version of `StateService.includes`: is the state (or glob
pattern, e.g. `'admin.**'`) included in the current active state? A
state name `RouteTypes` registers narrows `current` and `params`.

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `stateOrName` | [`StateOrName`](https://ui-router.github.io/core/docs/latest/modules/_state_interface_.html#stateorname) |
| `params?` | [`RawParams`](https://ui-router.github.io/core/docs/latest/interfaces/_params_interface_.rawparams.html) |

##### Returns

`boolean`
