Skip to Content
Documentation

SEO

Page metadata

Set the title, meta description, robots tag and canonical URL of VitNode pages from a plugin route's head or an app route's pageHead.

Every VitNode page builds its <title>, meta description, robots tag and canonical link from one small object returned by the route's head. VitNode adds the site name, the Open Graph tags and the X card tags for you.

Name the site

The site name comes from metadata in src/vitnode.config.ts. Each page title is {page} - {shortTitle ?? title}:

src/vitnode.config.ts
export const vitNodeConfig = buildConfig({
  metadata: {
    title: 'Acme Community',
    shortTitle: 'Acme', 
  },
  // ...
})

A page titled Pricing then gets <title>Pricing - Acme</title>.

Set metadata on a plugin page

A plugin page returns plain fields from head in its page module. head runs after load, so it can use the loaded data, and t translates keys from the route's messages:

plugins/site-notes/src/pages/note-page.tsx
import { defineRoute } from '@vitnode/core/tanstack/plugin-routes'

export const route = defineRoute({
  load: async ({ params }) => await fetchNote(params.id),
  head: ({ loaderData, t }) => ({
    title: loaderData?.title ?? t('site-notes.note.not_found'),
    description: loaderData?.summary,
  }),
})

fetchNote stands for your own query. Write head after load: TypeScript infers loaderData from load and reads members in order. Route module lists every field head accepts.

Set metadata on an app route

An app's own file routes call pageHead from @vitnode/core/tanstack/metadata, which takes the same fields and returns TanStack Router's meta and links:

apps/web/src/routes/_main/pricing.tsx
import { createFileRoute } from '@tanstack/react-router'
import { pageHead } from '@vitnode/core/tanstack/metadata'

import { PRICING_DESCRIPTION, PRICING_TITLE } from '@/site/pricing/metadata'

export const Route = createFileRoute('/_main/pricing')({
  head: () =>
    pageHead({
      title: PRICING_TITLE,
      description: PRICING_DESCRIPTION,
      canonical: '/pricing',
    }),
})

Keep the strings in a leaf file without UI imports, so head does not pull components into the client entry bundle. See Performance.

Keep a page out of search results

Set robots to one of three values:

ValueUse it for
index, followA normal public page. Same as leaving robots out.
noindex, followA view of other pages, such as a filtered or sorted list: its links still count
noindex, nofollowA page with nothing for search, such as a member's own files
plugins/site-notes/src/pages/notes-page.tsx
export const route = defineRoute({
  head: ({ search, t }) => ({
    title: t('site-notes.notes.title'),
    robots: search.tag ? 'noindex, follow' : 'index, follow', 
  }),
})

A deeper route's robots replaces its parent's. On a preview deployment, seo.indexing: false adds noindex on top of whatever a page says.

Don't also block such a page in robots.txt: a crawler has to fetch the page to read its noindex.

Point to the canonical URL

canonical tells search engines which URL is the original when the same page is reachable at several, for example with query parameters. Pass an absolute URL or a path on the site; it also becomes og:url. A page that exists in several languages sets alternates instead, which writes the canonical link and the hreflang links together. See Canonical and hreflang.

Check the result

Print the tags of a page:

curl -s http://localhost:3000/pricing | grep -oE '<title>[^<]*</title>|<meta [^>]*name="(description|robots)"[^>]*>|<link [^>]*rel="canonical"[^>]*>'

You should see the suffixed title, the description, the canonical link and, when set, the robots tag. The same page also carries og:* and twitter:* tags; see Social images.