Skip to content
brought to you byVoidZero

Pages Adapters ​

Install the adapter for your framework to use Pages Routing.

Error components ​

All four adapters export PageError and ErrorPageProps for _not-found and _error components:

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 }.

Build a URL with routeUrl() and pass it to Link's href. All four adapters use the Href type for links.

The router's visit(destination, options?), prefetch(destination, options?), and flush(destination, method?) accept RouteUrlInput: a string, URL, or typed destination object.

With 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 for framework examples.

Prefetching ​

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

ts
type LinkPrefetchStrategy = 'hover' | 'click' | 'mount' | 'visible';
ValueLoads the page
'hover' or trueWhen 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
falseNever

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 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:

OptionDefaultDescription
defaultStrategyfalseThe 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.
hoverDelay75Milliseconds 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).

ExportUsage
LinkRenders 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 set by middleware, loaders, or actions.
useForm(url, defaults, options?)Manage a form bound to a page action. Submit with post, put, patch, or delete.
useIslandForm(defaults)Manage a form in an island. Pass the action URL to each submit method. With typed routes, the URL must be a RouteUrl.
action(url, options?)Run a page action and await its ActionResult. 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 or aria-current="page", and the pending destination with data-void-pending.

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, viewTransitions to enable animated navigation, scrollRestoration to restore the saved scroll position on back/forward and reload (default true), and deployRecovery to control reloading after a deployment (default true).

@void/vue ​

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 and vue for the included @vitejs/plugin-vue plugin. Use appSetup to configure the Vue app.

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 ​

Import the 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 ​

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 and react for the included @vitejs/plugin-react plugin.

React Runtime ​

Import the 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.

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 ​

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 ​

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 and svelte for the included @sveltejs/vite-plugin-svelte plugin.

Svelte Runtime ​

Import the shared runtime API from @void/svelte. The adapter uses Svelte 5 runes.

@void/solid ​

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 and solid for the included vite-plugin-solid plugin.

Solid Runtime ​

Import the 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 ​

Install @void/md alongside your Pages adapter and add voidMarkdown() to your Vite plugins. See Markdown Pages for setup.

Import pathContents
@void/md/pluginvoidMarkdown(options?), MarkdownOptions, MdPage
@void/mduseFrontmatter(), MdPage
@void/md/pagesGenerated metadata for Markdown pages, used for navigation, sidebars, and search indexes
@void/md/theme.cssFull Markdown theme styles
@void/md/theme-content.cssContent-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.

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.