Skip to main content

Starwind UI v3.0 is now available! Migration guide

React Router Installation

Use this guide for React Router framework mode. If you added React Router to a Vite app, follow 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.

Install with the CLI

The CLI checks your React Router config, Vite config, app/root.*, and stylesheet before making changes. It installs the Starwind packages, connects the stylesheet, and adds the theme script to app/root.*.

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

The @/* import shortcut points to app/, 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>;
}

Manual Setup

Follow these steps to set up Starwind by hand. You can also use them to check the files changed by the CLI.

Complete the shared manual setup with the React package. 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. */

Add ThemeInitScript to the <head> in app/root.*.

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 />;
}

If you already have a Starwind theme script, keep it. You only need one.

Custom Project Setup

The CLI needs React Router framework mode with Vite and the Tailwind Vite plugin already set up. It checks the required files before installing packages or making changes. For a different project structure, follow the manual steps above.

See Dark Mode for theme controls.