---
url: >-
  https://lit-ui-router.dev/reference/ui-router-server/index/functions/routesFromStates.md
---
[ui-router-server](../../index.md) / [ui-router-server](../index.md) / routesFromStates

# Function: routesFromStates()

```ts
function routesFromStates<S>(states): StateRoutes<S>;
```

Defined in: [state-routes.ts:94](https://github.com/simshanith/lit-ui-router/blob/1a559af0dc04d61d71ea4536fe2398902475b4ce/packages/ui-router-server/src/state-routes.ts#L94)

A mount's routes from the app's data-only state declarations: each state's
[RouteDeclaration](../../redirects/interfaces/RouteDeclaration.md) fields (`name`, `parent`, `url`, `params`,
`redirectTo`, `redirectStatusCode`, `delegate`, `response`), with every
other field (`data`, `component`, `resolve`, ...) dropped. Literal names
and markers carry through, so an `as const` module still types the router.

Throws for a state whose routing a mount would get wrong: a nameless
state, a function or `TargetState` `redirectTo`, or an abstract state with
a url. `otherwise` and url config stay on the mount; hand the same
[url config](../../url-config/interfaces/RouterUrlConfig.md) to `applyUrlConfig` on the
client.

## Type Parameters

| Type Parameter |
| ------ |
|  `S` *extends* readonly [`RouteDeclaration`](../../redirects/interfaces/RouteDeclaration.md)\[] |

## Parameters

| Parameter | Type |
| ------ | ------ |
| `states` | `S` |

## Returns

[`StateRoutes`](../type-aliases/StateRoutes.md)<`S`>

## Example

```ts
import type { StateDeclaration } from '@uirouter/core';
import { routesFromStates } from 'ui-router-server';
import type { MountConfig } from 'ui-router-server';

// states.ts: data only, imported by the client states and vite.config.ts.
const states = [
  { name: 'home', url: '/' },
  { name: 'item', url: '/items/:id', data: { title: 'Item' } },
  { name: 'legacy', url: '/old', redirectTo: 'home' },
  { name: 'notFound' },
] as const satisfies readonly StateDeclaration[];

const mounts = {
  '/': { routes: routesFromStates(states), otherwise: { state: 'notFound' } },
} satisfies Record<string, MountConfig>;
```
