Choose declarative, data or framework mode
Choose how much routing infrastructure you need
React Router offers three modes. Declarative mode matches paths and navigates between elements, as in Chapter 21. Data mode adds route-associated loading, mutations, pending states and error handling. Framework mode adds a build integration and route-module conventions to the data features. Choose by application requirements, not by assuming that a more feature-rich mode is always better. The client fixtures below follow the React Router 7-style API lane; use a reviewed patched dependency set, not a historical install command. Current documentation also describes newer major releases. All examples are staged, not browser-tested.
import React from 'react';import { MemoryRouter, Routes, Route, Link } from 'react-router';export default function App() { return <MemoryRouter><nav><Link to="/">Library</Link>{' | '}<Link to="/hours">Hours</Link></nav> <main><Routes><Route path="/" element={<h1>Library</h1>} /> <Route path="/hours" element={<h1>Open 9–5</h1>} /></Routes></main> </MemoryRouter>;}The Hours link should replace the heading with Open 9–5. There is no route loader here; the text is embedded directly. This is sufficient for a small directory. For route-owned asynchronous data, a data router can coordinate navigation and loading instead of requiring each component to invent its own lifecycle.
Create a data router outside rendering
import React from 'react';import { createMemoryRouter, useLoaderData } from 'react-router';import { RouterProvider } from 'react-router/dom';function Hours() { const { hours } = useLoaderData(); return <main><h1>Library hours</h1><p>{hours}</p></main>;}const router = createMemoryRouter([{ path: '/', loader: () => ({ hours: '9–5' }), Component: Hours }]);export default function App() { return <RouterProvider router={router} />; }The loader supplies an object before the destination component consumes it. The expected screen is Library hours followed by 9–5. The router is constructed once outside React rendering: recreating it in every render can reset navigation and data state. Use createMemoryRouter for isolated history, createBrowserRouter for a browser URL. Do not mount another router around RouterProvider. A client Data mode loader runs in the client in this setup; a name such as loader does not make it server code.
Framework route modules and execution boundaries
import React from 'react';export async function loader() { return { branch: 'North library' };}export default function LibraryRoute({ loaderData }) { return <main><h1>{loaderData.branch}</h1></main>;}In an appropriately configured Framework mode project, register this file as a route in the framework route configuration. The route component receives loaderData and would display North library. The module is not a standalone client app; it needs the framework build, route registration and compatible runtime. With a server-enabled Framework integration, loader and action can run on the server, and clientLoader/clientAction provide client execution where supported. SSR produces initial HTML on a server; hydration attaches client behavior. Neither SSR nor these exports automatically imply React Server Components. Framework tooling can generate route-specific TypeScript types from the route config (for example Route.LoaderArgs and Route.ComponentProps via generated +types files); type generation and a typecheck require the actual framework project. Never send secrets in returned loader data. Authorization belongs on the server, including every data access and mutation.
Migration: v6 data routers introduced in the 6.4 era are not the same as older component-only routing. Review the version-specific upgrade guides, enable applicable future flags and test each step. Remix v2 projects have a migration path to React Router v7 Framework mode; later upgrades require their own runtime and dependency checks. Do not assume a package rename completes a migration. Framework mode can support server rendering or client-oriented deployment depending on configuration. A separate query cache is useful for shared client data outside route ownership; avoid storing independent competing copies of the same record.
Practice
Choose a mode for a static reading guide, a client dashboard needing route loading, and a server-rendered catalog. Explain where each loader runs and who checks authorization.