All articles
Web Development

SEO for React and Vite Sites: How to Make a Single-Page App Rank on Google

Why client-rendered React apps struggle in search, and the practical fixes: prerendering, per-page titles and meta, canonical URLs, sitemaps, structured data and Core Web Vitals.

By IdeaGrow Team 9 min read

React and Vite make it fast to build a polished website, but a default single-page app (SPA) ships an almost empty HTML file and builds the page with JavaScript in the browser. People never notice. Search engines and link previews often do. This guide explains what goes wrong for SEO in a client-rendered app and walks through the fixes we use on our own sites, in the order that gives the biggest return.

Why a default SPA is hard for search engines

Open the page source of a fresh Vite + React project and you will find little more than this:

<div id="root"></div>
<script type="module" src="/assets/index-abc123.js"></script>

Google can render JavaScript, but it does so in a second, deferred pass. Until that pass happens, the page has no headings, no text and no links to follow. Other crawlers, such as Bing at times, social networks building link previews, and many AI and SEO tools, may never run your JavaScript at all. The result is slow indexing, missing pages and generic previews when someone shares a link.

  • One title for every page. The <title> and meta description in index.html are shared by every route unless you change them.
  • Soft 404s. An unknown URL still returns HTTP 200 with the app shell, so Google sees thousands of thin, identical pages.
  • No crawlable links. Navigation built with click handlers instead of real <a href> elements cannot be followed.
  • Slow first paint. Content appears only after the JavaScript bundle downloads and runs, which hurts Core Web Vitals.

Step 1: Serve real HTML for every route

The single most effective fix is to make sure each URL returns HTML that already contains its content. You have three main options:

  • Prerendering (static site generation). At build time, render every known route to its own index.html. Ideal for marketing sites, blogs and documentation, where content changes only when you deploy.
  • Server-side rendering (SSR). Render each request on a server. Needed when pages depend on live data, such as search results or user-generated content.
  • A framework that does it for you. Next.js, Remix or Astro handle rendering and routing out of the box, at the cost of migrating your project.

For most company websites, prerendering is the sweet spot. Vite supports an SSR build (vite build --ssr), and a short Node script can import that bundle, call renderToString for each route and write the result into dist/route/index.html. The browser then hydrates the page with hydrateRoot, so the site still behaves like an SPA after the first load.

After deploying, check with "View page source" (not DevTools, which shows the rendered DOM). If you can read your headings and paragraphs in the raw source, crawlers can too.

Step 2: Unique titles and meta descriptions

Every indexable page needs its own <title> and <meta name="description"> in the HTML that is served, not only set later by JavaScript. Keep a single route-to-metadata map in your code and use it both in the prerender step and in the client when the route changes.

  • Keep titles under roughly 60 characters and put the main topic first, followed by your brand.
  • Write descriptions of about 140 to 160 characters that summarize the page and give a reason to click.
  • Add Open Graph tags (og:title, og:description, og:image, og:url) so shared links look good on social networks and messaging apps.
  • Use one <h1> per page that matches the search intent of the title.

Step 3: Canonical URLs and clean routing

Duplicate URLs split ranking signals. The same page might be reachable with and without a trailing slash, through www and the bare domain, or under an old path you kept for backwards compatibility. Pick one version and declare it on every page:

<link rel="canonical" href="https://example.com/blog/my-post" />
  • Redirect http to https and www to the bare domain (or the reverse) with a permanent 301 at the host level.
  • Use the browser history router with real paths, not hash URLs like /#/about. Search engines ignore everything after the #.
  • Point legacy paths to the new one with a canonical tag or, better, a 301 redirect.

Step 4: Return proper 404s

Most SPA hosting setups rewrite every unknown path to index.html, which means a typo URL returns a 200 status and an empty shell. Google reports these as soft 404s and may treat your site as low quality. Generate a dedicated 404.html during the build and configure your host to serve it with a real 404 status for paths you did not prerender. On Vercel, Netlify and most static hosts, a file named 404.html in the output folder is picked up automatically once you remove the catch-all rewrite.

Step 5: sitemap.xml and robots.txt

Since your prerender script already knows every route, let it write sitemap.xml at the same time, so the sitemap can never drift out of date:

<url>
  <loc>https://example.com/blog/my-post</loc>
  <lastmod>2026-10-27</lastmod>
</url>

Leave out pages that should not appear in search, such as account deletion forms or thank-you pages. Reference the sitemap from robots.txt with a Sitemap: line and submit it once in Google Search Console. Do not block your /assets/ folder in robots.txt: Google needs the JavaScript and CSS to render and evaluate the page.

Step 6: Structured data

Structured data in JSON-LD format tells search engines exactly what a page is about and can unlock rich results. For a company site, the most useful types are Organization on the home page, Article or BlogPosting on each post, and BreadcrumbList for deeper pages. Render the JSON-LD script into the prerendered HTML, then validate it with Google's Rich Results Test.

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "My post title",
  "datePublished": "2026-10-27",
  "author": { "@type": "Organization", "name": "Example Co" }
}
</script>

Step 7: Performance and Core Web Vitals

Page experience is a ranking factor, and React apps can be heavy. Focus on the three Core Web Vitals:

  • Largest Contentful Paint (LCP), under 2.5 seconds. Prerendered HTML helps a lot. Also preload the hero image, serve images in WebP or AVIF, and avoid hiding the main content behind a loading spinner.
  • Interaction to Next Paint (INP), under 200 milliseconds. Split large bundles with React.lazy and dynamic import(), and keep heavy work off the main thread.
  • Cumulative Layout Shift (CLS), under 0.1. Give images and ad slots fixed dimensions, and load web fonts with font-display: swap and a matching fallback.

Measure with PageSpeed Insights for real-user field data and Lighthouse for lab data. Field data from the Chrome UX Report is what Google actually uses.

Step 8: Content and internal links

Technical SEO makes your pages eligible to rank. Content decides whether they do. Write pages that answer a specific question better than what already ranks, use descriptive headings, and link related pages to each other with real anchor text such as "Google Play launch checklist" rather than "click here". Internal links help crawlers discover new pages and pass authority from your strongest pages to newer ones.

Verify in Google Search Console

  1. Verify your domain in Search Console using a DNS record, so all subdomains and protocols are covered.
  2. Submit sitemap.xml and watch the Pages report for errors such as "Crawled - currently not indexed" or soft 404s.
  3. Use URL Inspection on a few key pages and open "View crawled page" to confirm Google sees your full content.
  4. Check the Core Web Vitals and Enhancements reports after a few weeks of traffic.

The checklist at a glance

  • Every route returns prerendered or server-rendered HTML with its real content.
  • Unique title, meta description and Open Graph tags per page.
  • Canonical tag on every page, one preferred domain, history routing instead of hash routing.
  • Real 404 status for unknown URLs.
  • Auto-generated sitemap.xml referenced from robots.txt and submitted to Search Console.
  • JSON-LD structured data validated with the Rich Results Test.
  • Core Web Vitals in the green, measured with field data.
  • Helpful content connected by descriptive internal links.

Keep reading