ui-router-server / ui-router-server / routesFromStates
Function: routesFromStates()
ts
function routesFromStates<S>(states): StateRoutes<S>;Defined in: state-routes.ts:94
A mount's routes from the app's data-only state declarations: each state's RouteDeclaration 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 to applyUrlConfig on the client.
Type Parameters
| Type Parameter |
|---|
S extends readonly RouteDeclaration[] |
Parameters
| Parameter | Type |
|---|---|
states | S |
Returns
StateRoutes<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>;