# React SEO for single-page apps: prerender, SSR, per-route meta tags and real 404s

> A React SPA sends an empty div to every crawler. How to prerender or server-render routes with React Router, set title and meta per route, and return real 404s.

Source: https://seofix.ai/blog/react-spa-seo  
Published: 2026-12-04  
Updated: 2026-11-02  
Author: SEOFix Team  
Category: Technical SEO  
Tags: Technical SEO, Guides  
Length: 1,666 words, 8 min read

A React single-page app sends crawlers the same nearly empty HTML on every URL: one `<div id="root">`, one script tag and whatever `<title>` is hard-coded in `index.html`. Google renders the JavaScript afterwards and can index the result, but titles, canonicals, links and status codes all depend on that render going well, and crawlers that don't run JavaScript get nothing. The fix for React SEO in a single-page app is to put each route's HTML on the server: prerender it at build time, render it per request, or move the content routes to a framework that does both. React Router's framework mode can do this to an existing Vite app one route at a time, so you don't need to rewrite anything.

## What a React SPA sends to Google

The default Vite + React template has this as its entire body ([create-vite](https://unpkg.com/create-vite/template-react-ts/index.html)):

```html
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
```

Check your own site the same way crawlers see it:

```bash
for path in / /pricing /blog/some-post /products/does-not-exist; do
  printf '%-28s ' "$path"
  curl -s -o page.html -w '%{http_code} ' "https://example.com$path"
  printf '%s | words: %s\n' "$(grep -o -i '<title>[^<]*' page.html | head -1)" \
    "$(sed -e 's/<script.*<\/script>//g' -e 's/<[^>]*>//g' page.html | wc -w)"
done
```

On a typical SPA every line comes back `200`, with the same title and a word count in single digits, including the product that doesn't exist. That's four SEO problems in one table:

1. **One title for every URL.** Per-route titles only appear after the JavaScript runs.
2. **No content and no links in the HTML.** Google has to render each page to find the text and the next URLs to crawl. Google says it queues `200` pages for rendering but ["the page may stay on this queue for a few seconds, but it can take longer than that"](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics). Most AI crawlers never render ([our test](https://seofix.ai/blog/do-ai-crawlers-render-javascript)).
3. **`200`** **for missing pages.** The server doesn't know which routes exist, so every typo and deleted product is a soft 404 candidate.
4. **Canonicals and robots tags set in the browser.** Google warns that a `noindex` in the initial HTML can stop rendering entirely, and that a canonical changed by JavaScript should match the one in the HTML ([Google](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics)).

What Google does with JavaScript in detail, and what breaks in its renderer, is in [Does Google crawl JavaScript?](https://seofix.ai/blog/does-google-crawl-javascript).

If you're on Create React App, note that React deprecated it in February 2025 and recommends migrating ["to a framework, or to migrate to a build tool like Vite, Parcel, or RSBuild"](https://react.dev/blog/2025/02/14/sunsetting-create-react-app).

## Three ways to get HTML on the server

| Option | What crawlers get | Needs a Node server? | Good for |
| --- | --- | --- | --- |
| Prerender at build (SSG) | Full HTML per listed URL | No, static hosting works | Marketing pages, docs, blogs, catalogues that change daily or less |
| Server-side rendering | Full HTML per request | Yes | Listings, search pages, content that changes constantly |
| Keep as SPA | Empty shell | No | Logged-in app screens that shouldn't rank anyway |

Most sites end up mixing them: prerender the public pages, server-render the few that change constantly, and keep the dashboard client-side. React's own guidance points the same way: the frameworks it recommends support client rendering, SPAs and static generation, and ["allow you to add server-side rendering on a per-route basis"](https://react.dev/learn/creating-a-react-app).

## Option 1: React Router framework mode (formerly Remix)

React Router's framework mode is what Remix became: the Remix team folded it into React Router v7 and now recommends React Router for new projects and upgrades ([Remix](https://remix.run/blog/merging-remix-and-react-router)). As of November 2026 the current major version is 8 ([React Router docs](https://reactrouter.com/start/framework/rendering)). For an existing SPA built on Vite with `<Routes>`, there is an official [adoption guide](https://reactrouter.com/upgrading/component-routes): you swap `@vitejs/plugin-react` for the React Router Vite plugin, add a config file and a root module, and then move routes into route modules one at a time.

The rendering choice is a config setting ([React Router](https://reactrouter.com/start/framework/rendering)):

```typescript
// react-router.config.ts
import type { Config } from '@react-router/dev/config'
import { getPostSlugs } from './app/lib/posts'

export default {
  ssr: false, // static hosting; set to true if you run a Node server
  async prerender({ getStaticPaths }) {
    const slugs = await getPostSlugs()
    return [
      ...getStaticPaths(), // every route without a dynamic segment
      ...slugs.map((s) => `/blog/${s}`),
    ]
  },
} satisfies Config
```

`prerender: true` alone covers static paths but ["will not include any dynamic paths (i.e., /blog/:slug)"](https://reactrouter.com/how-to/pre-rendering), which is why the function above lists slugs. The build writes `build/client/blog/my-first-post/index.html` for each path, and each page's `loader` runs at build time to fetch its data ([React Router](https://reactrouter.com/how-to/pre-rendering)):

```typescript
// app/routes/blog-post.tsx
import type { Route } from './+types/blog-post'
import { data } from 'react-router'
import { getPost } from '../lib/posts'

export async function loader({ params }: Route.LoaderArgs) {
  const post = await getPost(params.slug)
  if (!post) throw data('Not Found', { status: 404 })
  return post
}

export default function BlogPost({ loaderData }: Route.ComponentProps) {
  const post = loaderData
  return (
    <article>
      <title>{`${post.title} | Example Blog`}</title>
      <meta name="description" content={post.summary} />
      <link rel="canonical" href={`https://example.com/blog/${post.slug}`} />
      <h1>{post.title}</h1>
      <div dangerouslySetInnerHTML={{ __html: post.html }} />
    </article>
  )
}
```

With `ssr: true`, the same `throw data('Not Found', { status: 404 })` is how React Router documents [returning a real 404](https://reactrouter.com/how-to/status) from a server-rendered route. With `ssr: false` there is no server at request time, so check what your static host does with paths you didn't prerender: it should answer `404`, not serve the app shell with `200`.

Even with `ssr: false` and no prerender list, React Router's SPA mode server-renders the root route into `index.html` at build time, so your app shell and `HydrateFallback` are real HTML instead of an empty div ([React Router](https://reactrouter.com/how-to/spa)). It doesn't put page content in the HTML, but it's a cheap first step.

## Option 2: Next.js

Next.js's App Router fully implements React Server Components, and React's docs call it the most complete implementation of that architecture today ([React](https://react.dev/learn/creating-a-react-app)). Moving a Vite SPA to Next.js is a bigger change than adopting React Router's framework mode, because routing, data fetching and the build all change. Choose it when you also want React Server Components, image optimisation or incremental static regeneration. We covered the Next.js patterns (data in Server Components, `generateMetadata`, metadata streaming) in [Can AI crawlers see your site?](https://seofix.ai/blog/do-ai-crawlers-render-javascript).

One trap to know if you go this way: when `notFound()` runs after a `<Suspense>` boundary has started streaming, Next.js keeps the `200` status and adds `noindex` instead ([Next.js](https://nextjs.org/docs/app/api-reference/functions/not-found)). Look up the record before anything streams if you need a real `404`.

## Option 3: prerender a Vite app yourself

If you can't adopt a framework, React ships the primitive: `prerender` from `react-dom/static` renders a tree to static HTML and, unlike `renderToString`, waits for data and Suspense boundaries to resolve ([React](https://react.dev/reference/react-dom/static/prerender), [renderToString](https://react.dev/reference/react-dom/server/renderToString)). Vite's SSR guide describes the same approach, pre-rendering known routes "using the same logic as production SSR" ([Vite](https://vite.dev/guide/ssr)).

A minimal build step, assuming your app takes the URL as a prop and uses React Router's `StaticRouter` on the server:

```typescript
// scripts/prerender.tsx (run with tsx after `vite build` and `vite build --ssr src/entry-server.tsx`)
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { prerenderToNodeStream } from 'react-dom/static'
import { render } from '../dist/server/entry-server.js' // returns <StaticRouter location={url}><App/></StaticRouter>

const template = await readFile('dist/client/index.html', 'utf8')
const routes = ['/', '/pricing', '/about', ...(await fetchProductPaths())]

for (const url of routes) {
  const { prelude } = await prerenderToNodeStream(render(url))
  let html = ''
  for await (const chunk of prelude) html += chunk
  const out = `dist/client${url === '/' ? '' : url}/index.html`
  await mkdir(out.replace(/\/index\.html$/, ''), { recursive: true })
  await writeFile(out, template.replace('<div id="root"></div>', `<div id="root">${html}</div>`))
}
```

The client then calls `hydrateRoot` instead of `createRoot`. This works, but you now own a small framework: route lists, data fetching at build time, hydration mismatches, 404 handling. For more than a handful of routes, framework mode is less code to maintain.

Prerendering services that detect bots and serve them a rendered copy are the other shortcut. Google calls that dynamic rendering and describes it as a workaround; we went through the trade-offs in Dynamic rendering: when it's still used and how to move off it.

## Titles and meta tags per route in React 19

React 19 lets any component render `<title>`, `<meta>` and `<link>`, and React ["will always place the corresponding DOM element in the document head"](https://react.dev/reference/react-dom/components/title), canonical links included ([React](https://react.dev/reference/react-dom/components/link)). React Router now recommends these elements over its older `meta` route export ([React Router](https://reactrouter.com/start/framework/route-module)). Two rules from the React docs that trip people up:

- **Render one** **`<title>`** **at a time.** If two components render a title, ["React will place all of those titles in the document head"](https://react.dev/reference/react-dom/components/title) and browser and search engine behaviour is undefined. Put the title in the page component, not in a layout as well.
- **Pass a single string.** `<title>Results page {pageNumber}</title>` gives React two children and throws an error. Use a template literal: `<title>{`Results page ${pageNumber}`}</title>`.

In a pure client-rendered SPA these tags still only exist after the JavaScript runs. They help Google once it renders, and they help users' browser tabs, but they don't reach crawlers that read only the HTML. Pair them with prerendering or SSR.

## Links and routing

Google only follows `<a>` elements with an `href` ([Google](https://developers.google.com/search/docs/crawling-indexing/links-crawlable)). React Router's `<Link to="/pricing">` renders a real `<a href="/pricing">`, so it's fine. These aren't:

```typescript
<div onClick={() => navigate('/pricing')}>Pricing</div>          // no href
<a onClick={() => navigate('/pricing')}>Pricing</a>              // no href
<HashRouter>…</HashRouter>                                        // URLs like /#/pricing
```

Google says single-page apps should use the History API and not fragments, because it ["can't reliably resolve"](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics) fragment URLs. Use `BrowserRouter` or framework mode.

## Soft 404s when you can't change the server

If the SPA has to stay client-rendered for now, use one of Google's two documented workarounds on error views ([Google](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics)): redirect to a path that returns a real `404`, or add `noindex` with JavaScript. In React:

```typescript
function ProductPage() {
  const { slug } = useParams()
  const { data, status } = useProduct(slug)
  if (status === 'error' || (status === 'success' && !data)) {
    return (
      <>
        <title>Product not found</title>
        <meta name="robots" content="noindex" />
        <h1>Product not found</h1>
      </>
    )
  }
  // …
}
```

Never ship the reverse: a `noindex` in `index.html` that the app removes once data loads. Google may skip rendering a page whose initial HTML has `noindex`, so the removal never happens.

## Checking the whole site

Test one URL per route type, not one URL per site. SEOFix audits the raw HTML of every page it crawls, which is what non-rendering crawlers get, so an SPA template shows up as the same title, missing H1s and missing links across every page of that template. Full audits with the render sample enabled also compare up to 20 pages after headless Chromium rendering and flag `JS_DEPENDENT_CONTENT` where content only exists after JavaScript ([how it works and its limits](https://seofix.ai/help/javascript-rendering)). Each issue comes with a fix prompt you can paste into Claude Code, Codex or Cursor opened on the codebase ([fix prompts](https://seofix.ai/help/fix-prompts)).

## FAQ

### Can Google index a React single-page app?

Yes. Google renders JavaScript and can index client-rendered content. You're relying on rendering for titles, links and content, and on JavaScript workarounds for status codes, and crawlers that don't render still see an empty page.

### Do I need Next.js for React SEO?

No. React Router's framework mode prerenders and server-renders React apps, and can be adopted inside an existing Vite project. Next.js is a good choice if you want its other features.

### Is react-helmet still needed?

React 19 renders `<title>`, `<meta>` and `<link>` from any component and hoists them into `<head>` itself ([React](https://react.dev/reference/react-dom/components/meta)), which covers what most apps used a head manager for.

### Is prerendering the same as dynamic rendering?

No. Prerendering produces one HTML file per URL that every visitor gets, people and bots alike. Dynamic rendering detects bots and serves them a different, rendered response.

---

Want to see what your React app sends crawlers on every route? [Run a free audit](https://seofix.ai/): SEOFix crawls the HTML your server returns and groups what's missing by template.
