Fields

Link

A link to a page, a URL or a media file, that keeps working when the page moves.

A link points to a document with a permalink, to a URL or to a media file. The admin shows one input that searches your pages and also takes a typed URL.

The link field in the admin

Example

cms/blocks/hero.ts
fields: {
  heading: { type: "text", required: true },
  cta: { type: "link", required: true },
  download: { type: "link", allowed: ["file"] },
}

A read adds the current URL of the target as href, and its title as title:

hero.cta;
// {
//   reference: { collection: "pages", id: "…" },
//   href: "/about/team",
//   title: "Our team",
//   target: "_self",
// }

A link to a page stores the page's id, not its URL. When the page moves to another URL, the link follows.

Render it

{hero.cta?.href && (
  <a href={hero.cta.href} target={hero.cta.target}>
    {hero.cta.title ?? hero.cta.href}
  </a>
)}

A link to a deleted or unpublished document reads as href: null and broken: true. Check href before you render the link.

Picking a target

The link-open field in the admin
  • Type to search the collections with a permalink, or paste a URL. Relative URLs like /contact work too.
  • target sets where the link opens. The admin offers the same tab (_self) and a new tab (_blank).
  • suffix adds a query or an anchor to the target's URL, like #pricing or ?ref=hero.

A link cannot be filtered and cannot be unique.

Options

What the link can point to. "internal" is a document with a permalink, "external" a typed URL and "file" a media file. Default: all three.