SEO Skill
Written by AI and Ian Nuttall

Ian Nuttall

More than 20 years in SEO. Founder of Practical Programmatic, a programmatic SEO course with over 1,000 students, and of URL Monitor, sold for $250,000.

AI writes these pages. I plan each one, gather the data from real sources and review the draft before it goes live.

See my background

React SEO

A React single-page app sends crawlers an empty page until JavaScript runs. Prerender the pages you want found, keep every head tag in the HTML, and crawl the build the way a crawler does. Tested on React 19.3 and React Router 8.5.

Short answer

A React single-page app is hard for search because the first HTML is an empty shell. Google renders the JavaScript later, but ChatGPT's, Claude's and Perplexity's crawlers don't run it, so they see nothing. Prerender every page you want found, so each one is HTML with its own title, description and canonical before anyone asks for it. Then crawl the build without JavaScript to see what those crawlers get.

Give this prompt to Claude Code

Set up SEO Skill in Claude Code so you can work on my site's SEO with my own Search Console data. Do every step yourself and only stop when you need me.

Claude Code installs the CLI, adds the hosted MCP server, waits while you sign in with Google and checks it connects. New accounts get $1 of free research once a Search Console site is connected, with no card.

Claude Code setup guide

What does the React SEO setup cover?

Every part of the setup that a search engine or AI agent reads, in the order you build it, each with the code to copy.

Most React SEO problems come from one fact: a single-page app built with Vite sends the same near-empty index.html for every URL, and the page appears only when the JavaScript runs. Google renders it later. The crawlers behind ChatGPT, Claude and Perplexity don’t, according to Vercel’s study of AI crawlers, and neither do most link previews.

This guide turns a Vite React app into one that sends real HTML for every page, with React Router’s prerendering. Every example was built with react-router build, served as static files and crawled before and after.

The examples use one content module so they fit together. Replace it with your CMS or API:

// app/lib/guides.ts
export const site = process.env.SITE_URL ?? 'https://example.com'

export const guides = [
  {
    slug: 'first-guide',
    title: 'First guide',
    description: 'The first guide on Example.',
    body: 'Some useful words about the first topic, written for people and agents.',
  },
]

export const getGuide = (slug: string) => guides.find((guide) => guide.slug === slug)

What do crawlers see in a React single-page app?

An empty shell. We crawled a fresh React Router app in its single-page mode, the setup most Vite React apps have, with the seo CLI and JavaScript turned off. The crawl reached one page out of three. It had no title or H1 and no links for the crawl to follow, and a made-up URL answered 200 instead of 404.

The same crawl with --rendering on found all three pages with their titles, because a browser ran the JavaScript first. That gap is the problem. Google sees roughly the second crawl, some time later. The AI crawlers see the first.

Run both crawls on your own app before you change anything. Serve the build with any static server, then:

npx -y seo crawl http://localhost:4173 --rendering off
npx -y seo crawl http://localhost:4173 --rendering on

Which React pages should be prerendered?

Every page you want found. A prerendered page is written to an HTML file during the build, so a crawler gets the content and links on the first request with no JavaScript. React Router does it in framework mode, which runs on Vite. Set ssr to false for static hosting and list the paths:

// react-router.config.ts
import type { Config } from '@react-router/dev/config'
import { guides } from './app/lib/guides'

export default {
  ssr: false,
  prerender: ['/', '/sitemap.xml', '/llms.txt', ...guides.map((guide) => `/guides/${guide.slug}`)],
} satisfies Config

react-router build prints a line for each file it writes, such as Prerender (html): /guides/first-guide -> build/client/guides/first-guide/index.html. A page that isn’t in that list is still a single-page app page, so check it if you want it in search. With prerender: true React Router writes every path without a parameter, but you still list dynamic paths like /guides/:slug yourself. The pre-rendering guide covers both.

Route data moves from clientLoader to loader, which runs during the build:

// app/routes/guide.tsx
import { data } from 'react-router'
import { Seo } from '../components/Seo'
import { getGuide, site } from '../lib/guides'
import type { Route } from './+types/guide'

export function loader({ params }: Route.LoaderArgs) {
  const guide = getGuide(params.slug)
  if (!guide) throw data(null, { status: 404 })
  return guide
}

export default function Guide({ loaderData: guide }: Route.ComponentProps) {
  const path = `/guides/${guide.slug}`
  const jsonLd = {
    '@context': 'https://schema.org',
    '@type': 'Article',
    headline: guide.title,
    description: guide.description,
    url: `${site}${path}`,
  }
  return (
    <main>
      <Seo title={guide.title} description={guide.description} path={path} />
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd).replace(/</g, '\\u003c') }}
      />
      <h1>{guide.title}</h1>
      <p>{guide.body}</p>
    </main>
  )
}

If you’d rather render on a server for every request, TanStack Start and Next.js do that too. The Next.js SEO guide covers the App Router.

How do I set titles, descriptions and canonicals in React?

Render the tags in the page. Since React 19, a <title>, <meta> or <link> in any component goes into the document head, and prerendering writes it into the HTML file. You don’t need react-helmet or react-helmet-async for this. One small component keeps every page consistent:

// app/components/Seo.tsx
import { site } from '../lib/guides'

type Props = { title: string; description: string; path: string }

export function Seo({ title, description, path }: Props) {
  const url = `${site}${path}`
  return (
    <>
      <title>{`${title} | Example`}</title>
      <meta name="description" content={description} />
      <link rel="canonical" href={url} />
      <meta property="og:title" content={title} />
      <meta property="og:description" content={description} />
      <meta property="og:url" content={url} />
      <meta property="og:type" content="website" />
    </>
  )
}

Render exactly one Seo per page. React puts every <title> it finds into the head, and two titles leave Google to pick one (the title reference warns about this). Give <title> one string, such as the template literal above. React expects its children to be a single piece of text.

Set the canonical on every page, including the home page. A canonical copied from a layout tells Google every page is the home page.

How do I add JSON-LD to a React page?

Add a <script type="application/ld+json"> in the page, as in the route above. Escape < as \u003c so a value in your data can’t close the script tag early. Prerendering writes the script into the HTML, so crawlers that don’t run JavaScript read it too.

Describe only what the page shows. An Article for a guide, a Product for a product page, and nothing for a page that is neither. Test the output in Google’s Rich Results Test.

How do I add a sitemap to a React app?

Write it from the same data as your routes, as a resource route that is prerendered like a page. Add it to app/routes.ts with route('sitemap.xml', 'routes/sitemap.ts') and to the prerender list:

// app/routes/sitemap.ts
import { guides, site } from '../lib/guides'

export function loader() {
  const urls = [`${site}/`, ...guides.map((guide) => `${site}/guides/${guide.slug}`)]
  const body = urls.map((url) => `  <url><loc>${url}</loc></url>`).join('\n')
  return new Response(
    `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${body}\n</urlset>\n`,
    { headers: { 'Content-Type': 'application/xml' } },
  )
}

The build writes build/client/sitemap.xml. Every URL in it comes from the same list as the prerendered pages, so the sitemap can’t list a page that doesn’t exist. Leave lastmod out unless you know the real date each page changed.

llms.txt works the same way, as route('llms.txt', 'routes/llms.ts'), with a loader that returns plain text listing your main pages. Agents read it; search engines don’t use it for ranking.

What should robots.txt say in a React app?

Allow everything and point at the sitemap. Put the file in public, which Vite copies to the build as it is:

User-agent: *
Allow: /

Sitemap: https://example.com/sitemap.xml

Don’t block /assets or your JavaScript files. Google needs them to render any page that still depends on JavaScript.

How do I return real 404s from a React app?

Stop sending index.html for every URL. Most single-page app setups rewrite every path to index.html with a 200 status, so a deleted page looks like a live one and Search Console can report it as a soft 404. Once every page is prerendered, you don’t need that rewrite. Serve a 404 page with a 404 status instead.

When / is prerendered, React Router also writes __spa-fallback.html, which shows your route error boundary for any path it doesn’t know. Copy it to 404.html after the build:

{
  "scripts": {
    "build": "react-router build && cp build/client/__spa-fallback.html build/client/404.html"
  }
}

Then tell your host to serve it. On Cloudflare Workers static assets that is "not_found_handling": "404-page", which answers with the nearest 404.html and a 404 status (Cloudflare’s 404 page docs). In our test a made-up URL then returned 404 and showed the “could not be found” page from the root error boundary.

Use normal paths, not hash URLs like /#/pricing. Google ignores everything after the #, so it treats every hash URL as the home page (Google’s JavaScript SEO basics).

How do I check a React build before it ships?

Crawl it without JavaScript. Build with your local address as the site URL, so canonicals and sitemap URLs point at the copy you are crawling, and serve the files:

SITE_URL=http://localhost:4173 npm run build
npx -y sirv-cli build/client --port 4173

In a second terminal:

npx -y seo crawl http://localhost:4173 --rendering off --fail-on medium

On our test app, the same crawl went from one page with three high issues (no title, no links, unknown URLs answering 200) to every page with no high or medium issues. Your agent can run it for you after each change; ask it in plain words, like the prompts further down. SEO for developers covers staging and CI.

Sources

Tested with React 19.3.1, React Router 8.5.3 and Vite 8.4.1:

How do I check my React site with an AI agent?

Ask it. With SEO Skill, your agent crawls the build, reads Search Console and checks each part of this setup on your own React site.

  • See what crawlers see

    Build my React app, serve it locally and crawl it twice, once with --rendering off and once with --rendering on, then tell me what is missing without JavaScript

  • Check what is prerendered

    List every route in my React app and tell me which ones are not prerendered to HTML in the build

  • Check the 404s

    Request three made-up URLs on example.com and tell me which return a 404 status and which return 200

  • Check the head tags

    Check every HTML file in my build for one title, a description, one H1 and a canonical, and list any that miss one

  • Check Google's view

    Which pages on example.com does Search Console say are not indexed, and why?

React SEO questions

Is React bad for SEO?

React itself is fine. A React app that only renders in the browser is the problem, because its first HTML has no content, titles or links. Prerender or server-render the pages you want found and React sites rank like any other.

Does Google render JavaScript in a React app?

Yes. Google queues each page for rendering and reads the rendered HTML, but it can take a while, and an error in your code can leave the page empty. The AI crawlers from OpenAI, Anthropic and Perplexity don't run JavaScript at all, so they only see the first HTML.

Do I still need react-helmet or react-helmet-async?

Not on React 19. React renders title, meta and link tags from any component and moves them into the head, including in prerendered HTML. In an app that only renders in the browser, those tags still only exist after the JavaScript runs.

Should I use hash URLs such as /#/pricing?

No. Google ignores the part after the hash, so every hash URL is the home page to it. Use normal paths with the History API, which React Router does by default.

Can SEO Skill check my React app before it ships?

Yes. The seo CLI crawls a local build with no sign-in. With rendering off it reads the HTML the way AI crawlers do, and with rendering on it reads what a browser sees.

Check your React site with your agent

Add SEO Skill to your agent, sign in with the Google account that can read your Search Console, and ask it to crawl your build.

Give this prompt to Claude Code

Set up SEO Skill in Claude Code so you can work on my site's SEO with my own Search Console data. Do every step yourself and only stop when you need me.

Claude Code installs the CLI, adds the hosted MCP server, waits while you sign in with Google and checks it connects. New accounts get $1 of free research once a Search Console site is connected, with no card.

Claude Code setup guide