Skip to content

Commit 972184d

Browse files
docs: replace deprecated v1 createRouter/router.use with v2 (#1337)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2cbddb3 commit 972184d

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

docs/2.utils/4.security.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ If return value is not `false`, the request is handled and no further action is
103103

104104
```ts
105105
const app = new H3();
106-
const router = createRouter();
107-
router.use("/", async (event) => {
106+
app.all("/", async (event) => {
108107
const corsRes = handleCors(event, {
109108
origin: "*",
110109
preflight: {

docs/4.examples/validate-data.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const contentSchema = v.object({
4646
uuid: v.pipe(v.string(), v.uuid()),
4747
});
4848

49-
router.use(
49+
app.all(
5050
// You must use a router to use params
5151
"/content/:topic/:uuid",
5252
async (event) => {
@@ -166,7 +166,7 @@ const contentSchema = z.object({
166166
uuid: z.string().uuid(),
167167
});
168168

169-
router.use("/content/:topic/:uuid", async (event) => {
169+
app.all("/content/:topic/:uuid", async (event) => {
170170
const params = await getValidatedRouterParams(event, contentSchema.safeParse);
171171
if (!params.success) {
172172
// Handle validation errors
@@ -187,7 +187,7 @@ const contentSchema = v.object({
187187
uuid: v.pipe(v.string(), v.uuid()),
188188
});
189189

190-
router.use("/content/:topic/:uuid", async (event) => {
190+
app.all("/content/:topic/:uuid", async (event) => {
191191
const params = await getValidatedRouterParams(event, v.safeParser(contentSchema));
192192
if (!params.success) {
193193
// Handle validation errors

src/utils/cors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ export function appendCorsHeaders(event: H3Event, options: CorsOptions): void {
126126
*
127127
* @example
128128
* const app = new H3();
129-
* const router = createRouter();
130-
* router.use("/", async (event) => {
129+
* app.all("/", async (event) => {
131130
* const corsRes = handleCors(event, {
132131
* origin: "*",
133132
* preflight: {

0 commit comments

Comments
 (0)