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.*andvite.config.*.app/root.*and an existingapp/app.css,app/root.css, orapp/styles.cssfile.- The existing
@tailwindcss/viteplugin in the Vite configuration.
Create a React Router Project
Skip this step when the framework-mode project already exists.
pnpm dlx create-react-router@latest my-appnpx create-react-router@latest my-appyarn dlx create-react-router@latest my-appInstall with the CLI
cd my-apppnpx starwind@latest init --defaultscd my-appnpx starwind@latest init --defaultscd my-appyarn dlx starwind@latest init --defaultsThe 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.*.
| Purpose | Path |
|---|---|
| Styled components | app/components/starwind |
| Shared utilities | app/lib/utils |
| Starwind stylesheet | app/styles/starwind.css |
| Theme script | app/root.* |
The @/* import shortcut points to app/, so @/components/starwind/button resolves to app/components/starwind/button.
Add and Render Button
pnpx starwind@latest add buttonnpx starwind@latest add buttonyarn dlx starwind@latest add buttonimport { 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.
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.
@import "./styles/starwind.css";
/* Existing application styles remain here. */Add ThemeInitScript to the <head> in app/root.*.
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.