You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React Router is a multi-strategy router for React bridging the gap from React 18 to React 19. You can use it maximally as a React framework or as minimally as you want.
9
9
10
-
The router at the top of your app determines which features are available to the rest of the APIs. Each mode builds upon the previous to let you use as much or as little as you like.
10
+
## Getting Started
11
11
12
-
-**Declarative**: minimalist usage, just URL matching, active states, and navigating. Classic and clean. If you're using `<BrowserRouter>`, you're using declarative routing.
13
-
-**Data**: Everything from declarative but adds data features like loaders, actions, and pending states. If you're using `createBrowserRouter`, you're using data.
14
-
-**Framework**: Let React Router do it all with efficient bundling, code splitting, server rendering, and advanced type safety. If you're using `routes.ts`, you're using the framework.
12
+
There are three primary ways, or "modes", to use it in your app, so there are three guides to get you started.
15
13
16
-
Each API doc will list which modes in which it's available with this:
14
+
-[Declarative](./start/declarative/installation)
15
+
-[Data](./start/data/custom)
16
+
-[Framework](./start/framework/installation)
17
17
18
-
[MODES: framework, data, declarative]
19
-
20
-
## Declarative
18
+
Learn which mode is right for you in [Picking a Mode](./start/picking-a-router).
21
19
22
-
[modes: declarative]
20
+
## Using These Guides
23
21
24
-
[Get Started](./start/library/installation) with Declarative routing.
22
+
Across the docs you'll see the following icons:
25
23
26
-
Like previous versions, React Router can still be used as a simple, declarative routing library. Its only job will be matching the URL to a set of components, providing access to URL data, and navigating around the app.
24
+
[MODES: framework, data, declarative]
27
25
28
-
This strategy is popular for "Single Page Apps" that have their own frontend infrastructure and v6 apps looking for a stress free upgrade.
26
+
<p></p>
29
27
30
-
It's particularly good at offline + sync architectures where pending states are rare and users have long running sessions. Framework features like pending states, code splitting, server rendering, SEO, and initial page load times can be traded out for instant local-first interactions.
28
+
These icons indicate which mode the content is relevant to.
31
29
32
-
```tsx
33
-
ReactDOM.createRoot(root).render(
34
-
<BrowserRouter>
35
-
<Routes>
36
-
<Routepath="/"element={<Home />} />
37
-
<Routepath="dashboard"element={<Dashboard />}>
38
-
<Routeindexelement={<RecentActivity />} />
39
-
<Routepath="project/:id"element={<Project />} />
40
-
</Route>
41
-
</Routes>
42
-
</BrowserRouter>
43
-
);
44
-
```
45
-
46
-
## Data
47
-
48
-
[modes: data]
49
-
50
-
[Get Started](./start/framework/custom) building a custom framework with a data router.
51
-
52
-
The framework features are built on top of lower-level APIs in React Router. You can use these APIs directly for a lighter-weight usage of React Router, but you'll need to set up your own bundling and server rendering (if you want it).
30
+
Additional auto-generated reference documentation is available:
53
31
54
-
Some of the features include:
55
-
56
-
- Data loading with route loaders
57
-
- Data mutations with actions
58
-
- Concurrent mutations with fetchers
59
-
- Race condition handling
60
-
- Utilities to manage pending states
61
-
62
-
Routes and loaders are configured at runtime with `createBrowserRouter`.
Using a data router, you now have access to nearly every runtime API in React Router.
100
-
101
-
## Framework
102
-
103
-
[modes: framework]
104
-
105
-
[Get Started](./start/framework/installation) with React Router as a framework.
106
-
107
-
Building on top of the data mode, React Router can be used maximally as your React framework. In this setup, you'll use the React Router CLI and Vite bundler plugin for a full-stack development and deployment architecture. This enables React Router to provide a large set of features most web projects will want, including:
108
-
109
-
- Vite bundler and dev server integration
110
-
- hot module replacement
111
-
- code splitting
112
-
- route conventions with type safety
113
-
- file system or config-based routing
114
-
- data loading with type safety
115
-
- actions with type safety
116
-
- automatic revalidation of page data after actions
117
-
- SSR, SPA, and static rendering strategies
118
-
- APIs for pending states and optimistic UI
119
-
- deployment adapters
120
-
121
-
Routes are configured with `routes.ts` which enables React Router to do a lot for you. For example, it will automatically code-split each route, provide type safety for the parameters and data, and automatically load the data with access to pending states as the user navigates to it.
122
-
123
-
```ts
124
-
import {
125
-
typeRouteConfig,
126
-
route,
127
-
index,
128
-
layout,
129
-
prefix,
130
-
} from"@react-router/dev/routes";
131
-
132
-
exportdefault [
133
-
index("./home.tsx"),
134
-
route("about", "./about.tsx"),
135
-
136
-
layout("./auth/layout.tsx", [
137
-
route("login", "./auth/login.tsx"),
138
-
route("register", "./auth/register.tsx"),
139
-
]),
140
-
141
-
...prefix("concerts", [
142
-
index("./concerts/home.tsx"),
143
-
route(":city", "./concerts/city.tsx"),
144
-
route(":city/:id", "./concerts/show.tsx"),
145
-
route("trending", "./concerts/trending.tsx"),
146
-
]),
147
-
] satisfiesRouteConfig;
148
-
```
149
-
150
-
You'll have access to the Route Module API, which most of the other features are built on.
If you are caught up on future flags, upgrading from React Router v6 or Remix is generally non-breaking:
36
+
If you are caught up on future flags, upgrading from React Router v6 or Remix v2 is generally non-breaking. Remix v2 apps are encouraged to upgrade to React Router v7.
0 commit comments