Skip to main content

Starwind UI v3.0 is now available! Migration guide

React Router Installation

This guide covers React Router framework mode. A normal Vite SPA that uses React Router as a library follows the Vite React guide.

Requirements

  • React and React DOM 18 or newer.
  • react-router.config.* and vite.config.*.
  • app/root.* and an existing app/app.css, app/root.css, or app/styles.css file.
  • The existing @tailwindcss/vite plugin in the Vite configuration.

Create a React Router Project

Skip this step when the framework-mode project already exists.

Initialize Starwind

Starwind uses react-router.config.* to distinguish framework mode from a Vite SPA. It validates the Vite config, root route, and global stylesheet before it changes the project.

PurposePath
Styled componentsapp/components/starwind
Shared utilitiesapp/lib/utils
Starwind stylesheetapp/styles/starwind.css
Theme initialization ownerapp/root.*

The @/* alias points at the app/ source root, so @/components/starwind/button resolves to app/components/starwind/button.

Add and Render Button

app/routes/home.tsx
import { Button } from "@/components/starwind/button";
export default function Home() {
return <Button>Hello from React Router</Button>;
}

Framework Wiring

Complete the shared manual setup with the React adapter. Set @/* to ./app/*. The existing Vite configuration must include React Router and Tailwind.

vite.config.ts
import tailwindcss from "@tailwindcss/vite";
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [tailwindcss(), reactRouter()],
resolve: {
tsconfigPaths: true,
},
});

Import the Starwind stylesheet through the existing app stylesheet.

app/app.css
@import "./styles/starwind.css";
/* Existing application styles remain here. */

Render ThemeInitScript in the root document head.

app/root.tsx
import { ThemeInitScript } from "@starwind-ui/react/theme";
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
<ThemeInitScript />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
export default function App() {
return <Outlet />;
}

Initialization preserves an existing Starwind theme initializer and the existing CSS import order.

Support Boundaries

Automatic setup expects React Router framework mode with Vite and the Tailwind Vite plugin already configured. Declarative and data-mode Vite SPAs use the Vite React guide. Starwind rejects an incomplete framework host during preflight, before package installation or project mutation.

See Dark Mode for theme controls.