React Router v7 SEO: SSR, prerender and SPA mode for crawlers
React Router v7 SEO for AI crawlers: what ssr true, prerender and SPA mode put in the raw HTML, why clientLoader routes ship a fallback, and how to fix it.
By Crawlito · 8 min read
In short
- React Router framework mode defaults to ssr true, so each route's component and loader data are in the first HTML response unless the config changes or the route loads its data only in a clientLoader.
- With ssr false and no prerender list, React Router builds one index.html from the root route only, so every URL sends the same HTML and the root HydrateFallback instead of page content.
- With ssr false plus a prerender list, each listed path gets its own HTML file and may use a loader; other paths fall back to __spa-fallback.html when / is prerendered.
- A route with a clientLoader and no server loader server-renders its HydrateFallback, which is the only thing a crawler that does not run JavaScript reads for that part of the page.
- Throwing data('Not Found', { status: 404 }) from a loader gives a real 404 status, while SPA mode hosts usually answer unknown URLs with the fallback file and a 200.
On this page
- What each React Router setting sends to a crawler
- SPA mode: one index.html for every URL
- Prerender: static HTML without a runtime server
- Routes with only a clientLoader ship their HydrateFallback
- Titles and descriptions: meta export or React 19 elements
- Serving robots.txt and a sitemap from resource routes
- Returning real 404 statuses from loaders
- How to check what crawlers receive
- Frequently asked questions
- Check your routes
React Router v7 in framework mode server-renders by default, so a crawler that does not run JavaScript gets each route's real HTML. The settings that change this are ssr: false, which turns the app into a single-page app with one shared index.html, and route-level clientLoader exports, which send a HydrateFallback placeholder instead of the content. For pages you want AI crawlers to read, keep ssr: true or list the routes in prerender, load their data in a loader, and check the raw HTML of each route.
This post maps each rendering setting to what a crawler actually receives. If you are deciding whether to leave a plain React SPA, React SPA SEO: fixing the empty shell compares the options, and SSR vs CSR for SEO and AI search explains why raw HTML matters. Here the focus is the React Router config itself.
A note on versions: at the time of writing, the React Router docs site shows 8.5.1 as the latest release and keeps the 7.x docs at 7.18.5. The ssr, prerender and SPA mode behaviour below is documented the same way in both; the experimental API-only mode appears only in the current docs. React Router v7 is, in the docs' words, "the next major version of Remix after v2", so they also apply to apps upgraded from Remix.
What each React Router setting sends to a crawler
React Router's rendering strategies page lists client-side rendering, server-side rendering and static pre-rendering. The config reference says ssr defaults to true.
Config in react-router.config.ts | What is built | What a non-rendering crawler gets |
|---|---|---|
ssr: true (default) | A server build plus client assets | Full HTML per request, with loader data |
ssr: true with prerender: [...] | Static HTML for listed paths, server for the rest | Full HTML for every route |
ssr: false with prerender: [...] or true | Static HTML for listed paths, a fallback file for the rest | Full HTML for listed paths, the shared fallback for others |
ssr: false and no prerender (SPA mode) | One index.html rendered from the root route | The same document for every URL |
ssr: "unstable_api-only" (experimental, current docs only) | A root-only shell plus a runtime server for loaders and actions | The shell, unless paths are prerendered |
The rows that matter most are the last three. Everything else gives each URL its own HTML. The rendering page describes API-only mode as experimental and says it "may change in minor or patch releases"; without prerendering it builds the same root-only shell as SPA mode, so treat it like SPA mode for crawlers.
SPA mode: one index.html for every URL
The SPA mode guide says that with ssr: false, "the server build will no longer be generated", and the build writes an index.html that "will only render the root route". You deploy build/client to a static host and rewrite every path to that file, for example with a _redirects rule:
/* /index.html 200That rule is the crawler problem in one line. /pricing, /blog/launch and /no-such-page all return the same HTML with status 200. What that HTML contains is whatever the root route renders at build time, which the guide suggests is a HydrateFallback such as a loading screen:
// app/root.tsx in SPA mode
export function HydrateFallback() {
return <LoadingScreen />;
}So a non-rendering crawler reads your root layout, a spinner and one title for the whole site. In SPA mode a loader is allowed on the root route only, and it runs at build time, not per request. Data for other routes comes from clientLoader, which only runs in the browser.
The guide also points out that the root route is still server-rendered at build time, so routes must be SSR-safe: no window or other browser-only APIs during the initial render, even in SPA mode.
Prerender: static HTML without a runtime server
The pre-rendering guide is the fix when you want a static host. The build runs each listed path through your app "just like a server would" and writes two files per path to build/client: an .html file for document requests and a .data file for client navigations. The .html file is what a crawler gets.
prerender: true covers only static paths from routes.ts, not dynamic ones like /blog/:slug, because the parameter values are unknown. For content sites, return the dynamic paths from a function:
// react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
ssr: false,
async prerender({ getStaticPaths }) {
const slugs = await getPostSlugsFromCMS();
return [...getStaticPaths(), ...slugs.map((s) => `/blog/${s}`)];
},
} satisfies Config;Paths render one at a time by default; the object form prerender: { paths, concurrency: 4 } renders them in parallel.
Three rules from the guide affect SEO with ssr: false:
- Loaders only on prerendered routes. A
loaderis permitted on any route matched by aprerenderpath. A content route you forget to list cannot use a server loader at all. - No
headersoractionexports. There is no runtime server, and the guide says React Router "will error at build time" on these invalid exports. Cache andX-Robots-Tagheaders have to come from the host. - The fallback file moves. If
/is not prerendered, the SPA fallback isbuild/client/index.html. If/is prerendered, it isbuild/client/__spa-fallback.html, and the host rewrite must point there:
/* /__spa-fallback.html 200Any URL that is not in your list, including new blog posts published after the last build, gets that fallback. Rebuild when content changes, or keep ssr: true and prerender only the pages that change rarely. With ssr: true, paths that are not prerendered are server-rendered as usual.
Routes with only a clientLoader ship their HydrateFallback
This is the case that catches SSR apps. A route can fetch data in the browser with clientLoader. The client data guide says that when a route has no server loader, clientLoader.hydrate = true "is implied", and its example HydrateFallback renders the text "Skeleton rendered during SSR". The route module reference adds that on first load the route component renders only after the client loader finishes.
// app/routes/product.tsx: crawlers see the skeleton, not the product
export async function clientLoader({ params }: Route.ClientLoaderArgs) {
const res = await fetch(`/api/products/${params.id}`);
return res.json();
}
export function HydrateFallback() {
return <p>Loading product...</p>;
}The server sends "Loading product..." for that part of the page. If the product name, price and description live in this route, a crawler that does not execute JavaScript never sees them.
The fix is to load the content in a server loader. You can keep a clientLoader for later navigations: the data loading page says that when both exist, the loader is used for the initial SSR (or pre-rendering) and the clientLoader on subsequent client-side navigations.
export async function loader({ params }: Route.LoaderArgs) {
return getProduct(params.id); // in the first HTML response
}To find these routes, search the codebase for files that export clientLoader but not loader, then decide which of them hold public content.
Titles and descriptions: meta export or React 19 elements
Per-route titles and descriptions are rendered on the server in framework mode, so they reach the raw HTML. There are two documented ways:
- The
metaexport, rendered by<Meta />in the root<head>. The route module docs say the meta of the last matching route is used and "the entire meta descriptor array is replaced, not merged", so a child route that sets only a title drops the parent's description. Build each route's full array. TheMetaDescriptortype in React Router's source also acceptstagName: "link", which is how the example below adds a canonical link. - React's built-in
<title>and<meta>elements inside the route component. The route module docs say that since React 19 this is recommended over themetaexport.
export function meta({ loaderData }: Route.MetaArgs) {
return [
{ title: `${loaderData.name} | Acme` },
{ name: "description", content: loaderData.summary },
{ tagName: "link", rel: "canonical", href: loaderData.url },
];
}If you move to v8, its upgrade guide says v8 removed the deprecated data argument of meta (and matches[i].data); use loaderData, as above. The guide notes this change has no future flag, so you can make it while still on v7. In SPA mode none of this helps crawlers, because only the root route's head is in index.html.
Serving robots.txt and a sitemap from resource routes
A resource route is a route module that exports a loader or action but no default component. For responses meant for external consumers, the docs say to return a Response. That makes it a good place for a robots.txt or sitemap that depends on the environment or the CMS:
// app/routes.ts
import { type RouteConfig, index, route } from "@react-router/dev/routes";
export default [
index("routes/home.tsx"),
route("robots.txt", "routes/robots.ts"),
route("sitemap.xml", "routes/sitemap.ts"),
] satisfies RouteConfig;// app/routes/robots.ts
export function loader() {
const body = process.env.DEPLOY_ENV === "production"
? "User-agent: *\nAllow: /\n\nSitemap: https://example.com/sitemap.xml\n"
: "User-agent: *\nDisallow: /\n";
return new Response(body, {
headers: { "Content-Type": "text/plain; charset=utf-8" },
});
}The sitemap route works the same way with Content-Type: application/xml and the URLs your loaders know about. Three points to check:
- Resource routes need a runtime server. With
ssr: false, put a staticrobots.txtandsitemap.xmlinpublic/instead. - Link to them with a plain
<a>or<Link reloadDocument>, as the docs say, or React Router tries client-side routing. - The docs say throwing an
Errorfrom a resource route results in a 500. Google's robots.txt spec treats a 4xx as no robots.txt, but stops crawling the site for the first 12 hours of 5xx errors, so return a valid response even when the CMS is down. What crawlers do when robots.txt returns 404 or 500 covers other crawlers.
For what a good sitemap should contain, see XML sitemaps for AI discovery.
Returning real 404 statuses from loaders
With SSR, React Router can send a real status code. The status code guide shows a loader throwing data() with a status, which renders the nearest ErrorBoundary:
import { data } from "react-router";
export async function loader({ params }: Route.LoaderArgs) {
const post = await getPost(params.slug);
if (!post) {
throw data("Not Found", { status: 404 });
}
return post;
}Without this, a missing slug renders an empty template with status 200, which crawlers treat as a real page. In SPA mode and for non-prerendered paths with ssr: false, the host rewrite answers every unknown URL with the fallback and a 200, and no loader can change that. 404 status codes in single-page apps covers host-level workarounds.
How to check what crawlers receive
- Confirm the config. Open
react-router.config.tsand notessrandprerender. - Fetch routes without JavaScript. Compare titles and look for a phrase from the page body:
for p in / /pricing /blog/launch; do
echo "== $p"
curl -s "https://example.com$p" | grep -o '<title>[^<]*</title>'
done
curl -s https://example.com/pricing | grep -c "Starter plan"- Check statuses. A made-up URL should return 404:
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/no-such-page. - Check the build. After
react-router build, listbuild/clientand confirm every content path has anindex.html, not just__spa-fallback.html. - Search for client-only routes. Look for
HydrateFallbacktext such as "Loading" in the raw HTML of public pages.
With ssr: true on Node, React Router's default server entry streams the response and uses the isbot package to decide whether to wait for all content first. React streaming SSR and isbot explains which crawlers that check matches.
Frequently asked questions
Is React Router v7 good for SEO?
Yes, in framework mode with the default ssr: true or with prerendering, because each route's HTML and metadata are in the first response. SPA mode is the exception: every URL gets the same root-only document.
Can I use prerender on a static host like Netlify or GitHub Pages?
Yes. Set ssr: false, list the paths in prerender, deploy build/client, and rewrite other paths to the fallback file. Routes must not export headers or action.
Does a clientLoader hurt SEO?
Only when it is the route's sole data source for public content. Then the server sends the HydrateFallback, so add a server loader for the initial render and keep the clientLoader for later navigations if you need it.
Will server rendering get my React Router site cited in AI answers?
No one can promise that. Rendering removes a technical barrier so AI crawlers can read your pages; whether an assistant cites them depends on many things outside your site.
Check your routes
Run the curl loop on your most important routes after every change to react-router.config.ts. To see the raw HTML a crawler gets for one page without setting anything up, run the free check.
Filed under Platform guides. Topics: react, ssr, rendering, javascript, robots-txt