Overview

Router Schema

s.router(router, schema)

A shorthand for creating router configurations. This combines s.record(schema).router(router) into a single call.

Use this to define page routes in your application, where each key in the record represents a URL path.

Options:
router: Router

The router configuration (e.g., nextAppRouter for Next.js App Router).

nextAppRouter
schema: Schema

The schema for each route's content.

s.object({ title: s.string() })
Methods:
.validate: method

Custom validation function

Examples:
Basic Usage
import { s, c, nextAppRouter } from "@/val.config";

const pageSchema = s.object({ 
  title: s.string(),
  content: s.richtext()
});

export default c.define(
  "/app/(main)/docs/[[...slug]]/page.val.ts",
  s.router(nextAppRouter, pageSchema),
  {
    "/docs": {
      title: "Overview",
      content: [/* ... */],
    },
    "/docs/getting-started": {
      title: "Getting Started",
      content: [/* ... */],
    },
  }
);
Equivalent to
// s.router(nextAppRouter, schema) is shorthand for:
s.record(schema).router(nextAppRouter)