---
url: /frontend/validation/params.md
description: >-
  Refine page route params with the second defineRoute type argument - required,
  optional and splat params, numeric coercion, and the inline tuple rule.
---

The second type argument to a page's `defineRoute` is a tuple. Each position refines
the corresponding URL param, in path order.

```ts [pages/users/[id]/index.ts]
import { defineRoute } from "_/pages";

export default defineRoute<"users/[id]", [
  VRefine<number, { minimum: 1, multipleOf: 1 }>
]>();
```

`pages/users/[id]/page.tsx` renders the page. A request to `/users/abc` throws a
`ValidationError` before that component mounts; the nearest
[error file](/frontend/validation/errors.md) renders it.

## Numeric coercion

URL params arrive as strings. A param typed as `number` is coerced before validation -
`"123"` becomes `123`; `"abc"` stays a string and fails the number check.

```ts
export default defineRoute<"orders/[orderId]", [number]>();
```

`number` still allows decimals. For an integer, add `multipleOf: 1`:

```ts
export default defineRoute<"orders/[orderId]", [
  VRefine<number, { minimum: 1, multipleOf: 1 }>
]>();
```

## Multiple params

Positions map to params in path order. Refinements are positional, not name-based -
renaming `[id]` to `[userId]` changes nothing here.

```ts [pages/users/[id]/[view]/index.ts]
export default defineRoute<"users/[id]/[view]", [
  VRefine<number, { minimum: 1, multipleOf: 1 }>,  // id
  "profile" | "settings" | "data",                 // view
]>();
```

Positions are optional, but to refine the second param you must supply the first.

## Optional and splat params

`{id}` is optional, and `{...path}` is a splat.
The tuple refines the value the router produces:

```ts [pages/blog/{category}/index.ts]
export default defineRoute<"blog/{category}", [
  "news" | "guides" | "releases"
]>();
```

```ts [pages/files/{...path}/index.ts]
export default defineRoute<"files/{...path}", [
  string
]>();
```

Refinements for a splat describe the **element** type, not the array.
The array wrapping is done automatically, so do not write array notation in the tuple:

```ts [pages/docs/versions/{...numbers}/index.ts]
// ❌ WRONG: the tuple position describes an array of arrays
export default defineRoute<"docs/versions/{...numbers}", [
  Array<number>
]>();

// ❌ WRONG: same mistake with shorthand
export default defineRoute<"docs/versions/{...numbers}", [
  number[]
]>();

// ✅ provide the segment type only
export default defineRoute<"docs/versions/{...numbers}", [
  number
]>();
```

Splat values arrive as an array of segments. Numeric splat elements are coerced when
the refinement types them as numbers. A splat that is its own segment must be the last
segment; a splat inside a mixed segment can be followed by a suffix or later segments.

## Keep the tuple inline

The wrapping `[]` must be written literally in the type arguments. Aliases *inside* the
tuple are fine; an alias for the tuple itself is not.

```ts
// ✅
type UserID = VRefine<number, { minimum: 1, multipleOf: 1 }>;
export default defineRoute<"users/[id]", [UserID]>();

// ❌ the brackets are hidden
type Params = [UserID];
export default defineRoute<"users/[id]", Params>();
```

The second form typechecks, but the schema is not derived and the route's validation
does not run as declared. This is the same structural rule the backend applies.
[VRefine and the bracket rule ›](/validation/refine.md#keep-the-wrapping-brackets-literal)

## Reading the values

Read validated params with `useParams()` from `_/use` in every framework. It runs the
page's contract and returns coerced values - a `[number]` param comes back as a number.

```tsx
import { useParams } from "_/use";

const params = useParams<"users/[id]">();
// read params.id during render
```

The framework's own hook still returns raw router values:
`useParams()` from `react-router`, `@solidjs/router` or `vue-router`, and `useRoute().params`
in Vue. Use it when the raw strings are what the page wants.
[Hooks ›](/frontend/hooks.md#useparams)
