DEPLOYMENT

Deploy a React App as a Static Website

Decide whether your React app fits static hosting, prepare a build, and test client routes, environment values and browser APIs.

TL;DR: React can run entirely in the browser when your build produces an HTML entry point and assets. Publish that output on a static host; use SPA fallback for browser-routed URLs and keep private operations on a separate backend.

Introduction

“React app” describes how a site draws its interface, not necessarily how it should be hosted. Some apps generate a static bundle. Others rely on server rendering, database sessions or framework routes. Before choosing where to deploy a React app, find out what must happen when a visitor loads a page.

The easiest test is to build the project and serve only its generated files. Disconnect from the development server first; otherwise you can mistake a dev-server feature for something that will be available in production.

What is a static React deployment?

A static React deployment serves a prebuilt HTML document and JavaScript bundles that render or hydrate the interface in the browser. Vite commonly writes these files into dist/. An already-built folder can be published as a ZIP; on KairoBase an enabled npm runner can also compile a supported project from a locked source.

An application can call a separately hosted API even when its UI is static. Treat the API's access controls as the source of truth: a route guard in React improves navigation, but the browser user can still send requests directly.

Why running a production build matters

  • Dev servers resolve modules on demand; production sites refer to output files with specific paths and names.
  • A framework's dev server may fall back to index.html when an app route is refreshed. Production hosts only do that when configured to.
  • Client environment values are baked into the JavaScript bundle. They are discoverable by anyone who can load the app.

How React behaves on a static host

Choose your routing model

Browser routing makes paths such as /projects/42 look like normal addresses. The host must serve the SPA entry file when it does not find a real asset for that route. Hash routing uses paths like /#/projects/42, which can work without a host rewrite, but trades away cleaner URLs. If your builder produces an HTML file for every route, prefer those files for public landing pages and articles.

Decide where requests run

A dashboard might fetch a JSON API when it loads. In production, use its real HTTPS origin, and ensure its CORS rules allow only the intended browser origins. Error and loading states should still make sense when the API is temporarily offline. For a public marketing page, pre-rendering can make the content visible before JavaScript and network requests complete.

Check nested pages and missing assets

After publication, paste a deep route into a new tab. Then open an intentionally missing asset path. A sensible setup serves the app for a route like /settings, but returns a 404 for a nonexistent settings.js; generating HTML for the latter makes failures harder to diagnose. If you enable single-page app fallback in KairoBase, it applies to paths that do not look like asset files.

SetupUseful forFirst check
Browser SPADashboards and interactive applicationsDirect refresh and browser back/forward
Pre-rendered routesPublic pages that should load without JSCorrect HTML metadata on direct requests
Server renderingPer-request work or protected server actionsHost/runtime compatibility and authentication

Practical steps

  1. Run your production build and inspect dist/index.html, bundled JavaScript and referenced assets.
  2. Use an HTTP preview to test direct visits, refreshes, account state and one normal failure such as an unavailable API.
  3. Upload the generated folder as a static ZIP, or queue an npm build with build and dist where enabled.
  4. Verify public HTTPS, a nested route and browser console output. Record the release before relying on it.

Common mistakes

  • Publishing TypeScript source instead of the bundled output.
  • Treating an API route that exists in development as available on a static hosting origin.
  • Including a secret in a variable injected into the client bundle.

Frequently asked questions

Does a static React site need Node after publishing? Not when Node was used only to build the assets. The browser runs the resulting client code.

Where should a database secret live? On a backend that authenticates and authorizes the request. The browser should never receive it.

Is SPA fallback needed for all React projects? No. It is useful for direct requests to browser routes that do not have pre-rendered files.

Can I deploy React without GitHub? Yes. Upload the complete result of a successful build as a ZIP.

What if the home page is just white? Check the Console and Network panels for a missing bundle, a bad base path or a JavaScript error before changing hosting settings.

Conclusion

Treat a React deployment as a browser build unless your requirements prove you need a server runtime. Start at KairoBase’s npm build documentation, then use the Vite deployment guide to check asset paths. The React documentation gives context for choosing tooling.

Related reading