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
Copy file name to clipboardExpand all lines: docs/how-to/middleware.md
+4-15Lines changed: 4 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,17 +133,9 @@ function getLoadContext(req, res) {
133
133
134
134
## Quick Start (Data Mode)
135
135
136
-
### 1. Enable the middleware flag
136
+
<docs-info>Note there is no future flag in Data Mode because you can opt-into middleware by adding it to your routes, no breaking changes exist that require a future flag.</docs-info>
137
137
138
-
```tsx
139
-
const router =createBrowserRouter(routes, {
140
-
future: {
141
-
unstable_middleware: true,
142
-
},
143
-
});
144
-
```
145
-
146
-
### 2. Create a context
138
+
### 1. Create a context
147
139
148
140
Middleware uses a `context` provider instance to provide data down the middleware chain.
149
141
You can create type-safe context objects using [`unstable_createContext`][createContext]:
@@ -156,7 +148,7 @@ export const userContext =
156
148
unstable_createContext<User|null>(null);
157
149
```
158
150
159
-
### 3. Add middleware to your routes
151
+
### 2. Add middleware to your routes
160
152
161
153
```tsx
162
154
import { redirect } from"react-router";
@@ -216,17 +208,14 @@ export default function Profile() {
216
208
}
217
209
```
218
210
219
-
### 4. Add an `unstable_getContext` function (optional)
211
+
### 3. Add an `unstable_getContext` function (optional)
220
212
221
213
If you wish to include a base context on all navigations/fetches, you can add an [`unstable_getContext`][getContext] function to your router. This will be called to populate a fresh context on every navigation/fetch.
0 commit comments