navigate() calls and missing params are caught at compile time.
defineRoutes()
Define your route map. Theconst modifier preserves literal path types for type-safe navigation.
Signature
RouteConfig
| Property | Type | Description |
|---|---|---|
component | () => Node | Promise<{ default: () => Node }> | Component to render (supports lazy imports) |
loader | (ctx: { params, signal }) => Promise<T> | T | Data loader — runs before the component renders |
errorComponent | (error: Error) => Node | Fallback component when loader fails |
params | ParamSchema | Parse and validate route params (:id → number) |
searchParams | SearchParamSchema | Parse and validate search/query params |
children | RouteDefinitionMap | Nested routes (rendered via Outlet) |
prerender | boolean | Pre-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
| Parameter | Type | Description |
|---|---|---|
routes | TypedRoutes<T> | Compiled route list from defineRoutes() |
initialUrl | string | Override URL (used in SSR to set the server request URL) |
options | RouterOptions | Configuration for server navigation and prefetching |
RouterOptions
| Option | Type | Default | Description |
|---|---|---|---|
serverNav | boolean | { timeout?: number } | false | Enable server-side navigation (SSR prefetch on navigate) |
Router<T>
| Property | Type | Description |
|---|---|---|
current | RouteMatch | null | Current matched route (reactive) |
loaderData | unknown[] | Data from the matched route’s loader (reactive) |
loaderError | Error | null | Error from the loader, if any (reactive) |
searchParams | Record<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() | () => void | Clean up the router |
RouterView
Renders the component matched by the current route.Props
| Prop | Type | Description |
|---|---|---|
router | Router | Router instance |
fallback | () => Node | Component to render when no route matches |
Outlet
Renders nested child routes inside a layout component. Must be used within a component rendered byRouterView.
useRouter()
Access the router instance from any component in the tree. Must be called withinRouterContext.Provider (set up automatically by RouterView).
Signature
.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
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/Method | Type | Description |
|---|---|---|
sp[key] | unknown | Read a search param (reactive) |
sp[key] = value | — | Write a search param (batched, replaces URL) |
delete sp[key] | — | Remove a search param |
sp.navigate(partial, opts?) | void | Merge params and navigate. { push: true } creates history entry |
Object.keys(sp) | string[] | Current param names |
{ ...sp } | object | Snapshot 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.createLink()
Create a Link component factory bound to a router’s state. Used internally — most apps use the Link component viaRouterView setup.
LinkProps
| Prop | Type | Description |
|---|---|---|
href | string | Target URL |
children | string | (() => Node) | Link content |
activeClass | string | CSS class applied when the link matches the current route |
className | string | Base CSS class |
prefetch | 'hover' | Prefetch route data on hover |