Router

ReferenceSchema API

s.router()

A record whose keys are the routes of your site: one entry, one page.

Use it for

  • Blog posts, products and case studies, each at its own URL
  • Letting editors add a page without a developer

Router Schema

s.router(router, schema)

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.

In Val Studio

Options

routerRouter

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

nextAppRouter
schemaSchema

The schema for each route's content.

s.object({ title: s.string() })

Methods

.validate

Custom validation function

Examples

Basic Usage

TypeScript
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

TypeScript
// s.router(nextAppRouter, schema) is shorthand for:
s.record(schema).router(nextAppRouter)
See alsopage-router