Overview

Route Schema

s.route()

A string schema that represents a route path in your application. Route values are validated against all router modules (records with .router() or created with s.router()).

Use s.route() instead of s.keyOf() when you want to reference routes from page routers, as it automatically validates against all router modules in your application.

Methods:
.include: method

Constrain valid routes to those matching a regular expression pattern. Only routes that match this pattern will be considered valid.

s.route().include(/^\/api\//)
.exclude: method

Exclude routes matching a regular expression pattern. Routes that match this pattern will be considered invalid.

s.route().exclude(/^\/admin\//)
.validate: method

Custom validation function

.nullable: method

Allow null values

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

const navigationSchema = s.object({
  links: s.array(
    s.object({
      label: s.string(),
      href: s.route(), // Validated against all router modules
    })
  ),
});

export default c.define(
  "/content/navigation.val.ts",
  navigationSchema,
  {
    links: [
      { label: "Home", href: "/" },
      { label: "Docs", href: "/docs" },
      { label: "Pricing", href: "/pricing" },
    ],
  }
);
With Include Pattern
// Only allow API routes
const apiLinkSchema = s.object({
  label: s.string(),
  href: s.route().include(/^\/api\//),
});
With Exclude Pattern
// Allow all routes except admin routes
const publicLinkSchema = s.object({
  label: s.string(),
  href: s.route().exclude(/^\/admin\//),
});
Combining Include and Exclude
// API routes except internal ones
const externalApiLinkSchema = s.object({
  label: s.string(),
  href: s.route()
    .include(/^\/api\//)
    .exclude(/^\/api\/internal\//),
});