Skip to main content
The Vertz router provides type-safe, file-system-free routing with loaders, nested layouts, and search param parsing. Route patterns are inferred from your route map, so typos in navigate() calls and missing params are caught at compile time.

defineRoutes()

Define your route map. The const modifier preserves literal path types for type-safe navigation.

Signature

RouteConfig

PropertyTypeDescription
component() => Node | Promise<{ default: () => Node }>Component to render (supports lazy imports)
loader(ctx: { params, signal }) => Promise<T> | TData loader — runs before the component renders
errorComponent(error: Error) => NodeFallback component when loader fails
paramsParamSchemaParse and validate route params (:idnumber)
searchParamsSearchParamSchemaParse and validate search/query params
childrenRouteDefinitionMapNested routes (rendered via Outlet)
prerenderbooleanPre-render this route at build time (true = SSG, false = skip)
generateParams() => Record<string, string>[] | Promise<Record<string, string>[]>Generate param combinations for pre-rendering dynamic routes

createRouter()

Create a router instance from a route definition.

Signature

Parameters

ParameterTypeDescription
routesTypedRoutes<T>Compiled route list from defineRoutes()
initialUrlstringOverride URL (used in SSR to set the server request URL)
optionsRouterOptionsConfiguration for server navigation and prefetching

RouterOptions

OptionTypeDefaultDescription
serverNavboolean | { timeout?: number }falseEnable server-side navigation (SSR prefetch on navigate)

Router<T>

PropertyTypeDescription
currentRouteMatch | nullCurrent matched route (reactive)
loaderDataunknown[]Data from the matched route’s loader (reactive)
loaderErrorError | nullError from the loader, if any (reactive)
searchParamsRecord<string, unknown>Parsed search params (reactive)
navigate(input)<TPath extends keyof T & string>(input: { to: TPath, ... }) => Promise<void>Navigate to a route pattern with typed params
revalidate()() => Promise<void>Re-run the current route’s loader
dispose()() => voidClean up the router

RouterView

Renders the component matched by the current route.

Props

PropTypeDescription
routerRouterRouter instance
fallback() => NodeComponent to render when no route matches

Outlet

Renders nested child routes inside a layout component. Must be used within a component rendered by RouterView.

useRouter()

Access the router instance from any component in the tree. Must be called within RouterContext.Provider (set up automatically by RouterView).

Signature

In scaffolded apps, codegen writes .vertz/generated/router.d.ts, which augments useRouter() with your app’s route map so navigate() is typed by default. You can still pass a generic manually in non-generated setups.

useParams()

Read the current route’s parsed parameters.

Signature

When a params schema is defined on the route config, useParams() returns the parsed values (e.g., id as number instead of string).

useSearchParams()

Read and write the current route’s search (query) params as a reactive proxy. Reads trigger signal tracking; writes batch-navigate to update the URL.

With a search params schema

Define a schema on the route to get typed, coerced values:

Signatures

ReactiveSearchParams

Property/MethodTypeDescription
sp[key]unknownRead a search param (reactive)
sp[key] = valueWrite a search param (batched, replaces URL)
delete sp[key]Remove a search param
sp.navigate(partial, opts?)voidMerge params and navigate. { push: true } creates history entry
Object.keys(sp)string[]Current param names
{ ...sp }objectSnapshot of current params

SSR behavior

During SSR, reads return the values from the request URL. Writes throw an error in development to catch accidental server-side mutations.
Create a Link component factory bound to a router’s state. Used internally — most apps use the Link component via RouterView setup.

LinkProps

PropTypeDescription
hrefstringTarget URL
childrenstring | (() => Node)Link content
activeClassstringCSS class applied when the link matches the current route
classNamestringBase CSS class
prefetch'hover'Prefetch route data on hover

Types