---
url: https://void.cloud/reference/api/pages.md
description: Vite plugins and client runtimes for React, Vue, Svelte, and Solid pages.
---

# Pages Adapters {#framework-adaptors}

Install the adapter for your framework to use [Pages Routing](../../guide/pages-routing/overview).

## Error components

All four adapters export `PageError` and `ErrorPageProps` for [`_not-found` and `_error` components](../../guide/pages-routing/errors):

```ts
// Also exported by @void/react, @void/vue, @void/svelte, and @void/solid.
import type { ErrorPageProps, PageError } from 'void/pages';
```

`PageError` has a numeric `status` and a string `message`. `ErrorPageProps` contains `{ error: PageError }`.

## Navigation destinations {#navigation-destinations}

Build a URL with [`routeUrl()`](./types.md#routeurl-path-options) and pass it to `Link`'s `href`. All four adapters use the [`Href`](./types.md#route-types) type for links.

The router's `visit(destination, options?)`, `prefetch(destination, options?)`, and `flush(destination, method?)` accept [`RouteUrlInput`](./types.md#route-types): a string, `URL`, or typed destination object.

With [`routing.typedRoutes`](../config.md#routing-typedroutes), `href` and router strings must match one of your routes, or be a same-page or external URL. Without it, both accept any string.

See [Typed navigation](../../guide/pages-routing/overview.md#typed-navigation) for framework examples.

## Prefetching {#prefetching}

`Link`'s `prefetch` prop takes `true`, `false`, a strategy, or an array of strategies:

```ts
type LinkPrefetchStrategy = 'hover' | 'click' | 'mount' | 'visible';
```

| Value               | Loads the page                                                                                |
| ------------------- | --------------------------------------------------------------------------------------------- |
| `'hover'` or `true` | When the pointer rests on the link for `hoverDelay`, when it gets keyboard focus, or on touch |
| `'click'`           | When the mouse button or finger goes down, just before the click                              |
| `'mount'`           | As soon as the link renders                                                                   |
| `'visible'`         | Once the link has stayed in view for 300 ms. Links scrolled quickly past are skipped          |
| `false`             | Never                                                                                         |

Combine strategies with an array such as `['visible', 'hover']`. The first one triggered loads the page; later triggers reuse it.

Only same-origin GET links prefetch. `Link` skips prefetching when Chromium reports data saver or a 2G connection. Calling `router.prefetch()` explicitly still loads the page.

Following a prefetched link reuses its data when ready. If it is still loading, navigation starts a separate request so [deferred props](../../guide/pages-routing/loaders.md#deferred-props) can stream without delaying the page.

Set `cacheFor` in milliseconds or as a duration such as `'5m'`. To show cached data while refreshing it in the background, use a pair such as `['30s', '5m']`: the page stays fresh for 30 seconds and can be reused for up to 5 minutes.

Each adapter plugin's `prefetch` option sets app-wide values:

| Option            | Default | Description                                                                                                                                                                                                 |
| ----------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `defaultStrategy` | `false` | The `prefetch` value for every `Link` that doesn't set its own. A `Link`'s own `prefetch` replaces it, and `prefetch={false}` turns it off. Links with a non-GET `method` or `reloadDocument` don't use it. |
| `hoverDelay`      | `75`    | Milliseconds the pointer rests on a link before `'hover'` prefetches.                                                                                                                                       |
| `cacheFor`        | `'30s'` | The `cacheFor` value for every `Link` that doesn't set its own.                                                                                                                                             |

## Shared runtime API

Import these helpers from your framework's adapter (`@void/react`, `@void/vue`, `@void/svelte`, or `@void/solid`).

| Export                             | Usage                                                                                                                                                                                                                               |
| ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Link`                             | Renders an anchor for GET and a button for mutations. Accepts `href`, `method`, `data`, `prefetch`, `cacheFor`, `preserveScroll`, `preserveState`, `replace`, `reloadDocument`, `viewTransition`, `activeMatch`, and `onNavigate`.  |
| `useRouter()`                      | Read `url`, `path`, `query`, and `params`. Navigate with `visit` or `refresh`, and manage prefetched pages with `prefetch`, `flush`, and `flushAll`.                                                                                |
| `useParams()`                      | Read the current page's route parameters. Pass its pattern to type them, e.g. `useParams<'/users/[id]'>()`.                                                                                                                         |
| `useNavigation()`                  | Read `{ state, location, method }`. The state is `idle`, `loading`, or `submitting`. The location is the pending destination.                                                                                                       |
| `useShared()`                      | Read [shared data](../../guide/pages-routing/layouts.md#shared-data) set by middleware, loaders, or actions.                                                                                                                        |
| `useForm(url, defaults, options?)` | Manage a [form](#form) bound to a page action. Submit with `post`, `put`, `patch`, or `delete`.                                                                                                                                     |
| `useIslandForm(defaults)`          | Manage a form in an [island](../../guide/pages-routing/islands.md#forms). Pass the action URL to each submit method. With [typed routes](../config.md#routing-typedroutes), the URL must be a [`RouteUrl`](./types.md#route-types). |
| `action(url, options?)`            | Run a page action and await its [`ActionResult`](../../guide/pages-routing/actions-and-forms.md#action-helper). Accepts `data`, `params`, `preserveScroll`, and `method` (`POST` by default, or `PUT`, `PATCH`, or `DELETE`).       |
| `isVoidActionError(error)`         | Narrows a thrown action error to `VoidActionError`.                                                                                                                                                                                 |
| `isCallSiteActionError(error)`     | Recognizes expected action errors such as `409` or `422`.                                                                                                                                                                           |
| `getValidationErrors(body)`        | Reads field errors from `error.body`. Returns `null` when there are none.                                                                                                                                                           |

On GET links, `data` adds query parameters to the rendered `href`. Primitive values become strings and arrays become repeated keys. Void skips `null` and `undefined` and rejects nested objects. Only GET links accept `prefetch` and `reloadDocument`. Style the current link with [`data-void-active`](../../guide/pages-routing/overview.md#active-links) or `aria-current="page"`, and the pending destination with [`data-void-pending`](../../guide/pages-routing/overview.md#pending-links).

`useForm()` exposes `data`, `pending`, `errors`, `error`, `hasChanges`, `wasSuccessful`, and `recentlySuccessful`. Use `reset`, `setError`, `clearErrors`, and `clearError` to update the form. React and Solid also provide `setData`. Vue and Svelte island forms also provide `submit(url, method)`.

## Shared plugin options

All four adapter plugins accept [`prefetch`](#prefetching), [`viewTransitions`](../../guide/pages-routing/view-transitions.md) to enable animated navigation, [`scrollRestoration`](../../guide/pages-routing/overview.md#scroll-restoration) to restore the saved scroll position on back/forward and reload (default `true`), and [`deployRecovery`](../../guide/pages-routing/overview.md#after-a-deploy) to control reloading after a deployment (default `true`).

## `@void/vue` {#void-vue}

### `voidVue(options?)` {#voidvue-options}

```ts
import { voidVue } from '@void/vue/plugin';
import { defineConfig } from 'vite';
import { voidPlugin } from 'void';

export default defineConfig({
  plugins: [voidPlugin(), voidVue()],
});
```

`VoidVueOptions` accepts the [shared plugin options](#shared-plugin-options) and `vue` for the included `@vitejs/plugin-vue` plugin. Use `appSetup` to configure the [Vue app](#vue-app-setup).

### Vue app setup {#vue-app-setup}

To use a Pinia store in your Vue pages, install `pinia` in your app. Then set `appSetup` to the path of a setup module, relative to the project root.

```ts
// vite.config.ts
import { voidVue } from '@void/vue/plugin';
import { defineConfig } from 'vite';
import { voidPlugin } from 'void';

export default defineConfig({
  plugins: [voidPlugin(), voidVue({ appSetup: './src/vue-app.ts' })],
});
```

Create the store inside `setup(app)` so each server request gets its own instance. The optional `dehydrate()` and `hydrate(state)` functions let the browser start with the state the server used to render the page.

```ts
// src/vue-app.ts
import { createPinia } from 'pinia';
import type { App } from 'vue';

export default function setup(app: App) {
  const pinia = createPinia();
  app.use(pinia);

  return {
    dehydrate: () => pinia.state.value,
    hydrate(state: typeof pinia.state.value) {
      pinia.state.value = state;
    },
  };
}
```

Void calls `setup(app)` on the server for each request that renders a Vue app, and in the browser before mounting the page or an island. Keep setup and both state functions synchronous. Guard browser-only APIs with `if (!import.meta.env.SSR)`.

For a hydrated page, `dehydrate()` runs after rendering and before deferred callbacks. Its return value goes into the HTML, then `hydrate(state)` restores it before the page mounts. Each island gets its own store from `setup(app)`. Pass any server values an island needs as props.

### Vue Runtime {#vue-runtime}

Import the [shared runtime API](#shared-runtime-api) from `@void/vue`.

Vue GET navigation remounts the page so `useForm()` picks up the destination record's URL and defaults; layouts persist. Mutations and `router.refresh()` preserve page state by default. Set `preserveState` explicitly to override the default for navigation within the same record.

## `@void/react` {#void-react}

### `voidReact(options?)` {#voidreact-options}

```ts
import { voidReact } from '@void/react/plugin';
import { defineConfig } from 'vite';
import { voidPlugin } from 'void';

export default defineConfig({
  plugins: [voidPlugin(), voidReact()],
});
```

`VoidReactOptions` accepts the [shared plugin options](#shared-plugin-options) and `react` for the included `@vitejs/plugin-react` plugin.

### React Runtime {#react-runtime}

Import the [shared runtime API](#shared-runtime-api) from `@void/react`. React schedules navigations as transitions.

React `useForm()` accepts `onSuccess?: () => void | Promise<void>` and `onError?: (error: Record<string, string> | VoidActionError) => void | Promise<void>`. `pending` stays true until callbacks finish. See [submission callbacks](../../guide/pages-routing/actions-and-forms.md#react-submission-callbacks).

React Pages requires React 19. Read a deferred prop with `use()` inside `<Suspense>` and handle rejections with an error boundary. Import `Deferred<T>` from your adapter when annotating props. In React it is a `Promise<T>`. Vue, Svelte, and Solid expose `{ loading, value, error }`.

### React navigation completion {#react-navigation-completion}

By default, `await router.visit()` and `await router.refresh()` wait for React to commit the updated page and URL. You can also request this explicitly with `{ resolveOn: 'commit' }`.

When awaiting navigation inside `startTransition`, a `<form action>`, `useActionState`, or an async `useForm()` callback, pass `{ resolveOn: 'data' }`:

```tsx
startTransition(async () => {
  await saveUser();
  await router.refresh({ resolveOn: 'data' });
});

await router.visit('/account', { resolveOn: 'data' });
```

With `'data'`, the promise resolves when page data is ready, so the Action can finish before React commits. The transition can stay pending through Suspense.

The DOM and URL may still show the previous page after `await`. Use an effect or ref callback for work that needs the updated DOM.

## `@void/svelte` {#void-svelte}

### `voidSvelte(options?)` {#voidsvelte-options}

```ts
import { voidSvelte } from '@void/svelte/plugin';
import { defineConfig } from 'vite';
import { voidPlugin } from 'void';

export default defineConfig({
  plugins: [voidPlugin(), voidSvelte()],
});
```

`VoidSvelteOptions` accepts the [shared plugin options](#shared-plugin-options) and `svelte` for the included `@sveltejs/vite-plugin-svelte` plugin.

### Svelte Runtime {#svelte-runtime}

Import the [shared runtime API](#shared-runtime-api) from `@void/svelte`. The adapter uses Svelte 5 runes.

## `@void/solid` {#void-solid}

### `voidSolid(options?)` {#voidsolid-options}

```ts
import { voidSolid } from '@void/solid/plugin';
import { defineConfig } from 'vite';
import { voidPlugin } from 'void';

export default defineConfig({
  plugins: [voidPlugin(), voidSolid()],
});
```

`VoidSolidOptions` accepts the [shared plugin options](#shared-plugin-options) and `solid` for the included `vite-plugin-solid` plugin.

### Solid Runtime {#solid-runtime}

Import the [shared runtime API](#shared-runtime-api) from `@void/solid`.

Solid re-creates the page on GET navigation and whenever the route or its params change, so `useForm()` picks up the destination record's URL and defaults; layouts persist. Within the same record, back/forward, mutations, and `router.refresh()` keep the page and update its props in place, as do resolved deferred props, so read props inside JSX or memos instead of copying them in the component body. Set `preserveState` explicitly to override the default for navigation within the same record.

## Markdown Package {#markdown-package}

Install `@void/md` alongside your Pages adapter and add `voidMarkdown()` to your Vite plugins. See [Markdown Pages](../../guide/pages-routing/markdown.md) for setup.

| Import path                  | Contents                                                                                 |
| ---------------------------- | ---------------------------------------------------------------------------------------- |
| `@void/md/plugin`            | `voidMarkdown(options?)`, `MarkdownOptions`, `MdPage`                                    |
| `@void/md`                   | `useFrontmatter()`, `MdPage`                                                             |
| `@void/md/pages`             | Generated metadata for Markdown pages, used for navigation, sidebars, and search indexes |
| `@void/md/theme.css`         | Full Markdown theme styles                                                               |
| `@void/md/theme-content.css` | Content-only Markdown styles for apps that provide their own shell/layout                |

`FrontmatterContext` and `setFrontmatter()` are deprecated. Use `useFrontmatter()`.

## Form

Each Pages adapter exports `Form`. Pass the object returned by `useForm()` as `form`; `method` defaults to `post`. It renders validation and action errors, preserves controlled input, and respects known quota retry deadlines without submitting automatically. `renderError` customizes action-error presentation; Svelte uses a snippet. See [Actions and Forms](../../guide/pages-routing/actions-and-forms.md).

Pass `{ throwOnError: false }` as the third argument to `useForm()` to show HTTP failures inline. Validation errors populate `form.errors`; other HTTP failures populate `form.error`. React also calls `onError`. Unexpected failures still throw, and cancelled submissions don't set a form error. See [Handling action errors](../../guide/pages-routing/actions-and-forms.md#validation-errors).
