🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Comparisons••By Komal Nakrani

Astro vs React SPA (Vite): Which Should You Build?

Astro vs React as a Vite single-page app: Astro sends HTML for each page and adds React only where needed; a React SPA renders in the browser. When to use each.

#Astro#React#Vite#SPA#Comparison

In the Astro vs React question, the real comparison is usually Astro against a React single-page app built with Vite. Choose Astro for sites people read and find through search: marketing pages, blogs, docs, portfolios, stores. Choose a Vite React SPA for apps people use after logging in: dashboards, editors, internal tools. Astro can render React components too, so you don’t have to give React up to get Astro’s static HTML.

A Vite React SPA sends a nearly empty HTML file and a JavaScript bundle; React then builds every page in the browser. Astro builds each page to complete HTML ahead of time and ships JavaScript only for the components that need to be interactive. That one difference drives most of the trade-offs below.

Key Takeaways

  • Astro is not an alternative to React; it’s a framework that can use React components as islands.
  • A Vite React SPA renders in the browser, so first paint waits for JavaScript and crawlers see little HTML.
  • Astro renders HTML at build time and adds React only where a client:* directive asks for it.
  • SPAs keep state across navigation easily, which suits highly interactive apps behind a login.
  • A common split is an Astro site for public pages and a React SPA (or Astro page with client:only) for the app.

Astro vs a Vite React SPA at a glance

Astro Vite React SPA
Architecture Multi-page app (MPA), HTML per route Single-page app, one HTML shell
Where pages render Build time (or server per request) In the browser
JavaScript shipped Only for islands Whole app bundle up front (split by route if configured)
Initial HTML Full content Empty <div id="root"> until JS runs
Routing File-based, real URLs and pages Client-side router (React Router, TanStack Router)
SEO and AI crawlers Content is in the HTML Depends on crawlers running JavaScript
State across pages Per page; share via stores or transition:persist Lives in memory across navigation
Hosting Static host or server adapter Static host with SPA fallback to index.html

How each one renders a page

A Vite React SPA starts from index.html with one mount point. Everything visible comes from JavaScript:

// src/main.tsx (Vite React SPA)
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { BrowserRouter, Routes, Route } from 'react-router';
import Home from './pages/Home';
import Pricing from './pages/Pricing';

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/pricing" element={<Pricing />} />
      </Routes>
    </BrowserRouter>
  </StrictMode>,
);

The browser downloads the HTML shell, then the bundle, runs React, and only then paints the page. Navigation after that is fast, since no new HTML is requested.

In Astro, each route is a file that renders to HTML at build time. A React component becomes interactive only where you say so:

---
// src/pages/pricing.astro
import BaseLayout from '../layouts/BaseLayout.astro';
import PlanToggle from '../components/PlanToggle.tsx';
---
<BaseLayout title="Pricing" description="Plans for teams of every size.">
  <h1>Pricing</h1>
  <p>Simple plans, billed monthly or yearly.</p>
  <PlanToggle client:visible />
</BaseLayout>

The heading and copy arrive as HTML. PlanToggle is server-rendered too, then React hydrates it when it scrolls into view. Everything else on the page has no JavaScript. The client directive guide explains the client:load, client:idle, client:visible and client:only choices.

Performance

For content pages, Astro has the structural advantage. The browser can paint as soon as HTML arrives, and the JavaScript it downloads is limited to the islands on that page. A SPA has to download, parse and run the app bundle before anything appears, which affects Largest Contentful Paint on slower phones and networks. Code-splitting and lazy routes help, but the floor is still “React plus the route’s components”.

Where SPAs are faster is subsequent navigation inside an app: switching tabs in a dashboard doesn’t fetch a new document. Astro can get close on content sites with prefetch (loading linked pages before the click) and the <ClientRouter /> component for view transitions, but if the whole experience is one continuous app, the SPA model fits it better.

SEO and AI answer engines

This is the decisive factor for public sites. A SPA’s initial HTML contains no content. Google can render JavaScript, but rendering is queued and can be delayed, and many other crawlers, including link preview bots and several AI crawlers, read only the raw HTML. They see an empty page.

Astro’s pages contain their full text, headings, links, meta tags and structured data in the HTML response. Nothing has to run for a crawler to read them. If you want a page to rank or be cited by AI assistants, getting content into the HTML is the most important step, and Astro does it by default. The Astro SEO checklist covers the rest.

You can add server-side rendering or pre-rendering to a React app, but then you’re adopting a framework (React Router’s framework mode, Next.js, or Astro), not running a plain SPA anymore.

State and interactivity

SPAs make app-wide state simple: a React context or store survives every route change because the page never reloads. Complex UIs with drag and drop, real-time updates, optimistic updates and deep client routing are natural here.

In Astro, each page is a separate document, so in-memory state resets on navigation. Options:

  • Share state between islands on one page with a small store library like Nano Stores.
  • Persist an island across navigation with <ClientRouter /> and transition:persist.
  • Keep state in the URL, localStorage, or on the server.

That covers most site needs: carts, theme toggles, filters, forms. It’s more friction than a SPA for a full application.

Using React inside Astro

You can bring existing React components into Astro with one command:

npx astro add react

That installs @astrojs/react and updates astro.config.mjs. React components then work in .astro pages. Components that touch window or document during render can use client:only="react" to skip server rendering:

---
// src/pages/app.astro
import BaseLayout from '../layouts/BaseLayout.astro';
import Dashboard from '../components/Dashboard.tsx';
---
<BaseLayout title="Dashboard" description="Your account.">
  <Dashboard client:only="react" />
</BaseLayout>

This pattern lets one project hold both a static marketing site and a client-rendered app area. The React integration docs list the configuration options. Planning a React-to-Astro move? Read MPA vs SPA for the architectural background.

Choose Astro or a React SPA

Choose Astro if:

  • The pages need to be found in search or cited by AI tools.
  • Most pages are content with a few interactive parts.
  • First-load speed on mobile matters.
  • You want to keep using React components without making every page a React app.

Choose a Vite React SPA if:

  • The product sits behind a login and isn’t indexed.
  • It’s one continuous, highly interactive app with shared client state.
  • The team wants the simplest possible React setup with no server rendering.

Use both if: you have a public site and an app. Put the site in Astro and the app in a SPA at app.example.com, or inside Astro with client:only islands.

If the public site is a SaaS or product site, Astro themes in the Technology category include pricing, features and docs pages, built as plain Astro you can add React islands to.

Migrating a React SPA to Astro

  1. Create an Astro project and run npx astro add react.
  2. Copy your components folder across unchanged.
  3. Turn each route into a file in src/pages/; move data fetching into page frontmatter where possible.
  4. Render static components without a directive; add client:* only to interactive ones.
  5. Replace React Router links with plain <a href> tags.
  6. Move global CSS imports into a layout, then deploy and set redirects for any changed URLs.

The official migration guide from Create React App applies equally to Vite React projects.

FAQ

Is Astro better than React?

They do different jobs. React is a UI library; Astro is a framework that can render React components. For content sites, Astro with React islands usually beats a React SPA on load speed and SEO. For complex apps behind a login, a React SPA or full React framework is often a better fit.

Can I use React in Astro?

Yes. Run npx astro add react, then import .jsx or .tsx components into Astro pages. They render to HTML on the server, and become interactive in the browser only when you add a client:* directive.

Is a React SPA bad for SEO?

It’s harder. A SPA’s initial HTML has no content, so crawlers must run JavaScript to see the page. Google can do that with delays; many other crawlers and AI bots can’t. Pre-rendering or server rendering fixes it.

Should I use Vite or Astro for a new project?

Astro is built on Vite, so you get Vite’s dev server and build either way. Use plain Vite with React for a client-only app. Use Astro when you want pages rendered to HTML, content collections and islands.

Can Astro build a single-page app?

Partly. You can render a whole React app on one Astro page with client:only="react", or use <ClientRouter /> for SPA-style transitions between Astro pages. For a fully client-routed app, a dedicated SPA setup is simpler.