Skip to content

VexRouteMapper

VexRouteMapper = (props) => string[]

Defined in: packages/core/src/routes/types.ts:33

User-supplied function mapping one document to the public paths that render it.

Configured once as vex.config.ts’s routes.map. Deliberately a plain lookup with no I/O and no framework coupling: it answers “where does this document appear?” and nothing else, so every consumer that needs that answer can share one definition.

Called once per document state involved in a write, never once per write — so an update passes the before and after documents separately and a slug rename resolves BOTH the old and the new path without the map looping over them itself.

The collection slug and the document to resolve paths for.

CollectionSlug

The collection the document belongs to.

Partial<VexDocument>

The document to resolve paths for. Partial because a freshly created document is known to the client only by the id its mutation returned — _creationTime is assigned server-side and never reaches the caller.

string[]

The public paths that render props.doc. Return [] for a collection that renders no public page — that is the normal case for most collections, not an error.

const map: VexRouteMapper = ({ collection, doc }) => {
if (collection !== "pages") return []
const { slug } = doc
if (typeof slug !== "string") return []
return [slug === "home" ? "/" : `/${slug}`]
}