Installation & Basic Setup in React
From the React Router v7 cheat sheet · Installation & Setup · verified Jul 2026
Installation & Basic Setup
Installing React Router v7 and choosing between Library and Framework modes
typescript
# Library Mode (Classic SPA)
npm install react-router
# Framework Mode (Full-stack with Vite)
npm create vite@latest my-app -- --template react
npm install react-router
npm install -D @react-router/dev
// vite.config.ts (Framework Mode)
import { reactRouter } from "@react-router/dev/vite"
import { defineConfig } from "vite"
export default defineConfig({
plugins: [reactRouter()]
})
// Library Mode: main.tsx
import { createBrowserRouter, RouterProvider } from 'react-router'
const router = createBrowserRouter([
{
path: "/",
element: <Root />,
children: [
{ path: "about", element: <About /> },
{ path: "contact", element: <Contact /> }
]
}
])
createRoot(document.getElementById('root')!).render(
<RouterProvider router={router} />
)💡 Framework Mode includes SSR, data loading, and actions out of the box
⚡ Library Mode is lighter for SPAs, Framework Mode for full-stack apps
📌 Framework Mode uses file-based routing by default
🟢 Start with Library Mode if migrating from v6
setupinstallationconfiguration