You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4caa41c
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/guide/pages-routing/overview.md
+24-7Lines changed: 24 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,42 +153,48 @@ Render and prerender flags combine like this:
153
153
| Island page + `ssr = false`| Invalid. Island pages already use the island renderer. |
154
154
|`output: "static"` + `prerender` unset | Auto-prerender pages that have known paths, including client-only shells. |
155
155
156
-
Use the `Link` component for SPA navigation between pages. It renders an `<a>` tag that intercepts clicks and navigates without a full page reload:
156
+
### Typed navigation
157
+
158
+
Use the `Link` component for SPA navigation between pages. Build dynamic URLs with [`routeUrl()`](../type-safety.md#typed-urls-and-navigation) to check the route pattern and its parameters:
157
159
158
160
::: code-group
159
161
160
162
```tsx [React]
161
163
import { Link } from"@void/react";
164
+
import { routeUrl } from'void/routes';
162
165
163
166
<Linkhref="/users">Users</Link>
164
-
<Linkhref={`/users/${id}`}>View</Link>
167
+
<Linkhref={routeUrl('/users/:id', { params: { id } })}>View</Link>
165
168
```
166
169
167
170
```vue [Vue]
168
171
<script setup lang="ts">
169
172
import { Link } from '@void/vue';
173
+
import { routeUrl } from 'void/routes';
170
174
</script>
171
175
172
176
<template>
173
177
<Link href="/users">Users</Link>
174
-
<Link :href="`/users/${id}`">View</Link>
178
+
<Link :href="routeUrl('/users/:id', { params: { id } })">View</Link>
175
179
</template>
176
180
```
177
181
178
182
```svelte [Svelte]
179
183
<script>
180
184
import { Link } from "@void/svelte";
185
+
import { routeUrl } from 'void/routes';
181
186
</script>
182
187
183
188
<Link href="/users">Users</Link>
184
-
<Link href={`/users/${id}`}>View</Link>
189
+
<Link href={routeUrl('/users/:id', { params: { id } })}>View</Link>
185
190
```
186
191
187
192
```tsx [Solid]
188
193
import { Link } from"@void/solid";
194
+
import { routeUrl } from'void/routes';
189
195
190
196
<Linkhref="/users">Users</Link>
191
-
<Linkhref={`/users/${id}`}>View</Link>
197
+
<Linkhref={routeUrl('/users/:id', { params: { id } })}>View</Link>
192
198
```
193
199
194
200
:::
@@ -222,17 +228,28 @@ import { Link } from "@void/solid";
222
228
223
229
`prefetch` and `reloadDocument` work only with GET links. GET `data` becomes query parameters; use scalar values or arrays.
224
230
225
-
For programmatic navigation, use `useRouter()`:
231
+
For programmatic navigation, use `useRouter()`. Pass a typed destination object to `visit()`, `prefetch()`, or `flush()`:
226
232
227
233
```ts
228
234
import { useRouter } from'@void/vue'; // or "@void/react", "@void/svelte", "@void/solid"
You can also pass URL strings or `URL` instances to these router methods. See [Typed URLs and Navigation](../type-safety.md#typed-urls-and-navigation) for query values, fragments, and catch-all routes.
252
+
236
253
`router.visit()` updates the page in place for same-origin URLs. `http(s)` URLs on another origin get a full page load, and other schemes such as `javascript:` are rejected.
237
254
238
255
For dynamic route params, use `useParams()` from the same adapter package:
The `action()` helper gets the same type checking. See [Actions & Forms](./pages-routing/actions-and-forms) for the full API.
104
104
105
+
## Typed URLs and Navigation
106
+
107
+
Use `routeUrl()` from `void/routes` to build URLs from your app's page, HTTP, and WebSocket route patterns. For a page at `pages/users/[id].tsx`, the pattern is `/users/:id`:
108
+
109
+
```ts
110
+
import { routeUrl } from'void/routes';
111
+
112
+
const url =routeUrl('/users/:id', {
113
+
params: { id: 42 },
114
+
query: { tab: 'activity' },
115
+
hash: 'details',
116
+
});
117
+
// /users/42?tab=activity#details
118
+
```
119
+
120
+
Your editor autocompletes route patterns and parameter names. TypeScript checks that the route exists and all required parameters are supplied. Parameter values accept strings or numbers; Void encodes them for the URL. Query keys are chosen by your app, and values can be strings, numbers, booleans, or arrays of those values. Arrays become repeated query parameters; `null` and `undefined` values are omitted.
121
+
122
+
Pass the returned string to `Link`, a plain `<a>`, or `c.redirect()`. For programmatic navigation and `c.rewrite()`, you can pass a destination object directly:
Destination objects use the same parameter checking and URL encoding as `routeUrl()`. See [Pages Routing](./pages-routing/overview.md#typed-navigation) for links and router methods, and [Rewrites](../reference/api/rewrites.md#c-rewrite-destination) for server navigation.
136
+
137
+
For a catch-all page such as `pages/files/[...path].tsx`, use `/files/:path{.+}` and pass the full path as one value:
Route types update with the dev server. For CI or standalone typechecking, run `void prepare` and follow [Setup](#setup). The [API reference](../reference/api/types.md#void-routes) lists the URL helper and route types.
Copy file name to clipboardExpand all lines: docs/reference/api.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Use this reference to find public imports, signatures, and return types. For set
26
26
|[Database and seeding](./api/database.md)| Queries, operators, and seed scripts. |
27
27
|[KV, storage, AI, and logging](./api/resources.md)| Resource clients, cache revalidation, and logs. |
28
28
|[Deployment artifacts](./api/deploy.md)| Package built apps for managed deployment. |
29
-
|[Types](./api/types.md)|Handler context, route types, and head metadata.|
29
+
|[Types](./api/types.md)|Typed URLs, route types, handler context, and head metadata. |
30
30
|[Environment variables](./api/env.md)| Validated environment values and binding types. |
31
31
|[Pages adapters](./api/pages.md)| React, Vue, Svelte, Solid, and Markdown. |
32
32
@@ -64,7 +64,7 @@ Import Void's app-facing APIs from these paths:
64
64
|`void/limits`|`UsageLimit`, `UsageLimitData`, and `readUsageLimit`. AI and Sandbox limits reject with `UsageLimit`; uncaught limits in Void routes and Pages actions return structured HTTP 429 responses. |
65
65
|`void/isr`|`revalidate(options)` for on-demand ISR cache invalidation |
66
66
|`void/log`|`logger` structured logging helper |
67
-
|`void/routes`|`RouteMap` and `WebSocketRouteMap` stubs (types only) |
67
+
|`void/routes`|[`routeUrl()`](./api/types.md#routeurl-path-options), `RouteDestination`, `RoutePath`, `RouteOptions`, `RouteUrlInput`, and generated route maps|
68
68
|`void/queues`|`queues` proxy for sending messages to typed queues |
69
69
|`void/email`|`sendEmail`, `createEmail`, `defineEmail`, `parseEmail`, `replyEmail`, `MimeError`, `ParseEmailError`, and address, attachment, result, and handler types. See [Email](../guide/email.md). |
70
70
|`void/email/testing`|`createEmailTestHarness` and `createInboundTestHarness` to capture sends and deliver test messages to `email/` handlers. |
All four adapters support typed URLs through [`routeUrl()`](./types.md#routeurl-path-options). Pass the returned string to `Link`'s `href`.
12
+
13
+
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.
14
+
15
+
See [Typed navigation](../../guide/pages-routing/overview.md#typed-navigation) for framework examples.
Copy file name to clipboardExpand all lines: docs/reference/api/rewrites.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,24 @@ URL rewrites re-dispatch a request at a different internal path without changing
10
10
11
11
Re-dispatches the current request at `destination` and returns the resulting `Response`. The browser URL does not change — this is a server-side hop. If `destination` has no query string, the original request query is preserved. If `destination` includes a query string, it replaces the original query. `destination` must start with `/`; known generated routes autocomplete via [`RewriteDestination`](#rewritedestination), while arbitrary strings remain accepted for dynamic paths.
12
12
13
+
Pass a [`RouteDestination`](./types.md#route-types) object to check the route pattern and its parameters:
14
+
15
+
```ts
16
+
returnc.rewrite({
17
+
pathname: '/users/:id',
18
+
params: { id: 42 },
19
+
query: { tab: 'activity' },
20
+
});
21
+
```
22
+
23
+
For a typed redirect, build the URL with [`routeUrl()`](./types.md#routeurl-path-options):
`c.redirect()` merges request query parameters into internal destinations, with destination values taking precedence. Redirecting a [named action](../../guide/pages-routing/actions-and-forms.md#named-actions) to a GET page drops the action key: `POST /users/42?delete&tab=profile` redirects to `/users/42?tab=profile`. Redirects that preserve the request method keep the action key: `307` and `308`, or `301` and `302` after a `PUT`, `PATCH`, or `DELETE`.
|`params`| Route-specific | Required for dynamic routes. Each parameter accepts a `string` or `number`. |
115
+
|`query`|`RouteQuery`| Query parameters. Arrays become repeated keys; `null` and `undefined` are omitted. |
116
+
|`hash`|`string`| URL fragment, such as `'details'` or `'#details'`. |
117
+
118
+
Static routes accept optional `query` and `hash` options. Pass raw parameter values for URL encoding. Catch-all parameters preserve `/` separators between segments. Invalid or missing path parameters throw a `TypeError`.
119
+
120
+
Use the returned string with `Link`, `<a>`, and `c.redirect()`. See [Typed URLs and Navigation](../../guide/type-safety.md#typed-urls-and-navigation) for setup and examples.
0 commit comments