---
title: "React SEO guide for single-page apps | SEO Skill"
description: "React SEO for Vite single-page apps: prerender every page, set titles and canonicals without react-helmet, write a sitemap and return real 404s."
canonical: "https://seoskill.dev/guides/react-seo"
language: "en"
---

Written by AI and Ian NuttallX: 81.8kYouTube: 16.9kLinkedIn: 4.5k

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.

-   [81.8kfollowers on X](https://x.com/iannuttall)
-   [16.9ksubscribers on YouTube](https://www.youtube.com/@inuttall)
-   [4.5kfollowers on LinkedIn](https://www.linkedin.com/in/iannuttall)

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](https://seoskill.dev/about#ian-nuttall)

# 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.

## 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.

-   [What do crawlers see in a React single-page app?](#what-do-crawlers-see-in-a-react-single-page-app)
-   [Which React pages should be prerendered?](#which-react-pages-should-be-prerendered)
-   [How do I set titles, descriptions and canonicals in React?](#how-do-i-set-titles-descriptions-and-canonicals-in-react)
-   [How do I add JSON-LD to a React page?](#how-do-i-add-json-ld-to-a-react-page)
-   [How do I add a sitemap to a React app?](#how-do-i-add-a-sitemap-to-a-react-app)
-   [What should robots.txt say in a React app?](#what-should-robotstxt-say-in-a-react-app)
-   [How do I return real 404s from a React app?](#how-do-i-return-real-404s-from-a-react-app)
-   [How do I check a React build before it ships?](#how-do-i-check-a-react-build-before-it-ships)

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](https://vercel.com/blog/the-rise-of-the-ai-crawler), 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:

```ts
// 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](https://seoskill.dev/docs/crawl) 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:

```sh
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:

```ts
// 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](https://reactrouter.com/how-to/pre-rendering) covers both.

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

```tsx
// 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](https://seoskill.dev/guides/nextjs-seo) 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:

```tsx
// 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](https://react.dev/reference/react-dom/components/title) 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:

```ts
// 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:

```txt
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:

```json
{
  "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](https://developers.cloudflare.com/workers/static-assets/routing/static-site-generation/)). 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](https://developers.google.com/search/docs/crawling-indexing/javascript/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:

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

In a second terminal:

```sh
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](https://seoskill.dev/features/seo-for-developers) covers staging and CI.

## Sources

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

-   [React Router pre-rendering](https://reactrouter.com/how-to/pre-rendering) and [SPA mode](https://reactrouter.com/how-to/spa)
-   [React title component](https://react.dev/reference/react-dom/components/title), [React meta component](https://react.dev/reference/react-dom/components/meta) and [React link component](https://react.dev/reference/react-dom/components/link)
-   [Google’s JavaScript SEO basics](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics)
-   [Vercel on AI crawlers and JavaScript](https://vercel.com/blog/the-rise-of-the-ai-crawler)
-   [Cloudflare static assets and 404 pages](https://developers.cloudflare.com/workers/static-assets/routing/static-site-generation/)

## 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](https://seoskill.dev/docs/crawl) 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.

## Set up SEO Skill

Give this prompt to your AI agent. It installs the `seo` CLI, adds the hosted MCP server, waits while you sign in with Google and checks it connects.

```prompt
Set up SEO Skill in this agent 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.

1. If `seo --version` fails, install the SEO Skill CLI with `npm i -g seo`. If Node.js is missing or too old for it, install the current LTS release of Node.js yourself, such as with Homebrew, winget or nvm, and ask me only when it needs my password or approval.
2. Add the hosted MCP server https://seoskill.dev/mcp to this agent as a remote HTTP MCP server named seoskill, for every project. Use this agent's own command or config file and keep its other servers. If you cannot add MCP servers yourself, find this agent's steps at https://seoskill.dev/integrations and walk me through them.
3. Start this agent's MCP sign-in for seoskill, or tell me how to start it. I sign in with Google, which creates my free seoskill.dev account. Wait until it finishes.
4. Run `seo login`. It prints a link and a code. Show me both and ask me to open the link, sign in with the same Google account and click "Link this machine". Wait until I say it is done, then run `seo login` again to finish.
5. Run `seo skill install` to add the SEO skill.
6. Check that this agent lists seoskill as connected. If it does not, read the error and fix it.
7. Run `seo sites` and ask me which site to start with. If it lists none, tell me the Google account I used needs access to a Search Console property. Its last line shows my plan and how much usage is left: tell me that in a sentence.

When it's connected, tell me what to restart so the seoskill tools load, and give me a message to send afterwards that asks you to run seo_next for the site I picked. After that, use the seoskill MCP tools for my data. Call seo_next for the site I picked and do the step it returns. Use the `seo` CLI only for site crawls and Bing data, which run on my machine. Research such as keywords, competitors, backlinks and AI answers works without my own key: it uses my plan's usage or my free credit. A paid plan also sends pages to Google through seo_submit at $0.10 a URL from that usage, with no Index My Site sign-up. Show me the quote and ask before sending. If I connected my own Index My Site, use its credits instead. Bing through IndexNow is free. When a tool says I have used 50%, 80% or all of it, tell me in one line and offer the next step it gives, such as moving to the next plan. If a tool fails with USAGE_LIMIT, tell me that paid action is paused and keep going with the free tools. You can pick or change my plan, buy a top-up, set auto-reload or cancel with seo_account, but only after I say yes to that exact step and price. If it returns a Stripe link, give it to me to pay. Only add a site to the weekly site audit when I ask.
```

There are setup guides for [Claude Code](https://seoskill.dev/integrations/claude-code), [Codex](https://seoskill.dev/integrations/codex), [Cursor](https://seoskill.dev/integrations/cursor) and [every other agent](https://seoskill.dev/integrations).
