UNPKG

80.8 kBMarkdownView Raw
1# `react-router`
2
3## 7.6.2
4
5### Patch Changes
6
7- Avoid additional `with-props` chunk in Framework Mode by moving route module component prop logic from the Vite plugin to `react-router` ([#13650](https://github.com/remix-run/react-router/pull/13650))
8- \[INTERNAL] Slight refactor of internal `headers()` function processing for use with RSC ([#13639](https://github.com/remix-run/react-router/pull/13639))
9
10## 7.6.1
11
12### Patch Changes
13
14- Update `Route.MetaArgs` to reflect that `data` can be potentially `undefined` ([#13563](https://github.com/remix-run/react-router/pull/13563))
15
16 This is primarily for cases where a route `loader` threw an error to it's own `ErrorBoundary`. but it also arises in the case of a 404 which renders the root `ErrorBoundary`/`meta` but the root loader did not run because not routes matched.
17
18- Partially revert optimization added in `7.1.4` to reduce calls to `matchRoutes` because it surfaced other issues ([#13562](https://github.com/remix-run/react-router/pull/13562))
19
20- Fix typegen when same route is used at multiple paths ([#13574](https://github.com/remix-run/react-router/pull/13574))
21
22 For example, `routes/route.tsx` is used at 4 different paths here:
23
24 ```ts
25 import { type RouteConfig, route } from "@react-router/dev/routes";
26 export default [
27 route("base/:base", "routes/base.tsx", [
28 route("home/:home", "routes/route.tsx", { id: "home" }),
29 route("changelog/:changelog", "routes/route.tsx", { id: "changelog" }),
30 route("splat/*", "routes/route.tsx", { id: "splat" }),
31 ]),
32 route("other/:other", "routes/route.tsx", { id: "other" }),
33 ] satisfies RouteConfig;
34 ```
35
36 Previously, typegen would arbitrarily pick one of these paths to be the "winner" and generate types for the route module based on that path.
37 Now, typegen creates unions as necessary for alternate paths for the same route file.
38
39- Better types for `params` ([#13543](https://github.com/remix-run/react-router/pull/13543))
40
41 For example:
42
43 ```ts
44 // routes.ts
45 import { type RouteConfig, route } from "@react-router/dev/routes";
46
47 export default [
48 route("parent/:p", "routes/parent.tsx", [
49 route("layout/:l", "routes/layout.tsx", [
50 route("child1/:c1a/:c1b", "routes/child1.tsx"),
51 route("child2/:c2a/:c2b", "routes/child2.tsx"),
52 ]),
53 ]),
54 ] satisfies RouteConfig;
55 ```
56
57 Previously, `params` for the `routes/layout.tsx` route were calculated as `{ p: string, l: string }`.
58 This incorrectly ignores params that could come from child routes.
59 If visiting `/parent/1/layout/2/child1/3/4`, the actual params passed to `routes/layout.tsx` will have a type of `{ p: string, l: string, c1a: string, c1b: string }`.
60
61 Now, `params` are aware of child routes and autocompletion will include child params as optionals:
62
63 ```ts
64 params.|
65 // ^ cursor is here and you ask for autocompletion
66 // p: string
67 // l: string
68 // c1a?: string
69 // c1b?: string
70 // c2a?: string
71 // c2b?: string
72 ```
73
74 You can also narrow the types for `params` as it is implemented as a normalized union of params for each page that includes `routes/layout.tsx`:
75
76 ```ts
77 if (typeof params.c1a === 'string') {
78 params.|
79 // ^ cursor is here and you ask for autocompletion
80 // p: string
81 // l: string
82 // c1a: string
83 // c1b: string
84 }
85 ```
86
87 ***
88
89 UNSTABLE: renamed internal `react-router/route-module` export to `react-router/internal`
90 UNSTABLE: removed `Info` export from generated `+types/*` files
91
92- Avoid initial fetcher execution 404 error when Lazy Route Discovery is interrupted by a navigation ([#13564](https://github.com/remix-run/react-router/pull/13564))
93
94- href replaces splats `*` ([#13593](https://github.com/remix-run/react-router/pull/13593))
95
96 ```ts
97 const a = href("/products/*", { "*": "/1/edit" });
98 // -> /products/1/edit
99 ```
100
101## 7.6.0
102
103### Minor Changes
104
105- Added a new `react-router.config.ts` `routeDiscovery` option to configure Lazy Route Discovery behavior. ([#13451](https://github.com/remix-run/react-router/pull/13451))
106
107 - By default, Lazy Route Discovery is enabled and makes manifest requests to the `/__manifest` path:
108 - `routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" }`
109 - You can modify the manifest path used:
110 - `routeDiscovery: { mode: "lazy", manifestPath: "/custom-manifest" }`
111 - Or you can disable this feature entirely and include all routes in the manifest on initial document load:
112 - `routeDiscovery: { mode: "initial" }`
113
114- Add support for route component props in `createRoutesStub`. This allows you to unit test your route components using the props instead of the hooks: ([#13528](https://github.com/remix-run/react-router/pull/13528))
115
116 ```tsx
117 let RoutesStub = createRoutesStub([
118 {
119 path: "/",
120 Component({ loaderData }) {
121 let data = loaderData as { message: string };
122 return <pre data-testid="data">Message: {data.message}</pre>;
123 },
124 loader() {
125 return { message: "hello" };
126 },
127 },
128 ]);
129
130 render(<RoutesStub />);
131
132 await waitFor(() => screen.findByText("Message: hello"));
133 ```
134
135### Patch Changes
136
137- Fix `react-router` module augmentation for `NodeNext` ([#13498](https://github.com/remix-run/react-router/pull/13498))
138
139- Don't bundle `react-router` in `react-router/dom` CJS export ([#13497](https://github.com/remix-run/react-router/pull/13497))
140
141- Fix bug where a submitting `fetcher` would get stuck in a `loading` state if a revalidating `loader` redirected ([#12873](https://github.com/remix-run/react-router/pull/12873))
142
143- Fix hydration error if a server `loader` returned `undefined` ([#13496](https://github.com/remix-run/react-router/pull/13496))
144
145- Fix initial load 404 scenarios in data mode ([#13500](https://github.com/remix-run/react-router/pull/13500))
146
147- Stabilize `useRevalidator`'s `revalidate` function ([#13542](https://github.com/remix-run/react-router/pull/13542))
148
149- Preserve status code if a `clientAction` throws a `data()` result in framework mode ([#13522](https://github.com/remix-run/react-router/pull/13522))
150
151- Be defensive against leading double slashes in paths to avoid `Invalid URL` errors from the URL constructor ([#13510](https://github.com/remix-run/react-router/pull/13510))
152
153 - Note we do not sanitize/normalize these paths - we only detect them so we can avoid the error that would be thrown by `new URL("//", window.location.origin)`
154
155- Remove `Navigator` declaration for `navigator.connection.saveData` to avoid messing with any other types beyond `saveData` in userland ([#13512](https://github.com/remix-run/react-router/pull/13512))
156
157- Fix `handleError` `params` values on `.data` requests for routes with a dynamic param as the last URL segment ([#13481](https://github.com/remix-run/react-router/pull/13481))
158
159- Don't trigger an `ErrorBoundary` UI before the reload when we detect a manifest verison mismatch in Lazy Route Discovery ([#13480](https://github.com/remix-run/react-router/pull/13480))
160
161- Inline `turbo-stream@2.4.1` dependency and fix decoding ordering of Map/Set instances ([#13518](https://github.com/remix-run/react-router/pull/13518))
162
163- Only render dev warnings in DEV mode ([#13461](https://github.com/remix-run/react-router/pull/13461))
164
165- UNSTABLE: Fix a few bugs with error bubbling in middleware use-cases ([#13538](https://github.com/remix-run/react-router/pull/13538))
166
167- Short circuit post-processing on aborted `dataStrategy` requests ([#13521](https://github.com/remix-run/react-router/pull/13521))
168
169 - This resolves non-user-facing console errors of the form `Cannot read properties of undefined (reading 'result')`
170
171## 7.5.3
172
173### Patch Changes
174
175- Fix bug where bubbled action errors would result in `loaderData` being cleared at the handling `ErrorBoundary` route ([#13476](https://github.com/remix-run/react-router/pull/13476))
176- Handle redirects from `clientLoader.hydrate` initial load executions ([#13477](https://github.com/remix-run/react-router/pull/13477))
177
178## 7.5.2
179
180### Patch Changes
181
182- Update Single Fetch to also handle the 204 redirects used in `?_data` requests in Remix v2 ([#13364](https://github.com/remix-run/react-router/pull/13364))
183
184 - This allows applications to return a redirect on `.data` requests from outside the scope of React Router (i.e., an `express`/`hono` middleware)
185 - ⚠️ Please note that doing so relies on implementation details that are subject to change without a SemVer major release
186 - This is primarily done to ease upgrading to Single Fetch for existing Remix v2 applications, but the recommended way to handle this is redirecting from a route middleware
187
188- Adjust approach for Prerendering/SPA Mode via headers ([#13453](https://github.com/remix-run/react-router/pull/13453))
189
190## 7.5.1
191
192### Patch Changes
193
194- Fix single fetch bug where no revalidation request would be made when navigating upwards to a reused parent route ([#13253](https://github.com/remix-run/react-router/pull/13253))
195
196- When using the object-based `route.lazy` API, the `HydrateFallback` and `hydrateFallbackElement` properties are now skipped when lazy loading routes after hydration. ([#13376](https://github.com/remix-run/react-router/pull/13376))
197
198 If you move the code for these properties into a separate file, you can use this optimization to avoid downloading unused hydration code. For example:
199
200 ```ts
201 createBrowserRouter([
202 {
203 path: "/show/:showId",
204 lazy: {
205 loader: async () => (await import("./show.loader.js")).loader,
206 Component: async () => (await import("./show.component.js")).Component,
207 HydrateFallback: async () =>
208 (await import("./show.hydrate-fallback.js")).HydrateFallback,
209 },
210 },
211 ]);
212 ```
213
214- Properly revalidate prerendered paths when param values change ([#13380](https://github.com/remix-run/react-router/pull/13380))
215
216- UNSTABLE: Add a new `unstable_runClientMiddleware` argument to `dataStrategy` to enable middleware execution in custom `dataStrategy` implementations ([#13395](https://github.com/remix-run/react-router/pull/13395))
217
218- UNSTABLE: Add better error messaging when `getLoadContext` is not updated to return a `Map`" ([#13242](https://github.com/remix-run/react-router/pull/13242))
219
220- Do not automatically add `null` to `staticHandler.query()` `context.loaderData` if routes do not have loaders ([#13223](https://github.com/remix-run/react-router/pull/13223))
221
222 - This was a Remix v2 implementation detail inadvertently left in for React Router v7
223 - Now that we allow returning `undefined` from loaders, our prior check of `loaderData[routeId] !== undefined` was no longer sufficient and was changed to a `routeId in loaderData` check - these `null` values can cause issues for this new check
224 - ⚠️ This could be a "breaking bug fix" for you if you are doing manual SSR with `createStaticHandler()`/`<StaticRouterProvider>`, and using `context.loaderData` to control `<RouterProvider>` hydration behavior on the client
225
226- Fix prerendering when a loader returns a redirect ([#13365](https://github.com/remix-run/react-router/pull/13365))
227
228- UNSTABLE: Update context type for `LoaderFunctionArgs`/`ActionFunctionArgs` when middleware is enabled ([#13381](https://github.com/remix-run/react-router/pull/13381))
229
230- Add support for the new `unstable_shouldCallHandler`/`unstable_shouldRevalidateArgs` APIs in `dataStrategy` ([#13253](https://github.com/remix-run/react-router/pull/13253))
231
232## 7.5.0
233
234### Minor Changes
235
236- Add granular object-based API for `route.lazy` to support lazy loading of individual route properties, for example: ([#13294](https://github.com/remix-run/react-router/pull/13294))
237
238 ```ts
239 createBrowserRouter([
240 {
241 path: "/show/:showId",
242 lazy: {
243 loader: async () => (await import("./show.loader.js")).loader,
244 action: async () => (await import("./show.action.js")).action,
245 Component: async () => (await import("./show.component.js")).Component,
246 },
247 },
248 ]);
249 ```
250
251 **Breaking change for `route.unstable_lazyMiddleware` consumers**
252
253 The `route.unstable_lazyMiddleware` property is no longer supported. If you want to lazily load middleware, you must use the new object-based `route.lazy` API with `route.lazy.unstable_middleware`, for example:
254
255 ```ts
256 createBrowserRouter([
257 {
258 path: "/show/:showId",
259 lazy: {
260 unstable_middleware: async () =>
261 (await import("./show.middleware.js")).middleware,
262 // etc.
263 },
264 },
265 ]);
266 ```
267
268### Patch Changes
269
270- Introduce `unstable_subResourceIntegrity` future flag that enables generation of an importmap with integrity for the scripts that will be loaded by the browser. ([#13163](https://github.com/remix-run/react-router/pull/13163))
271
272## 7.4.1
273
274### Patch Changes
275
276- Fix types on `unstable_MiddlewareFunction` to avoid type errors when a middleware doesn't return a value ([#13311](https://github.com/remix-run/react-router/pull/13311))
277- Dedupe calls to `route.lazy` functions ([#13260](https://github.com/remix-run/react-router/pull/13260))
278- Add support for `route.unstable_lazyMiddleware` function to allow lazy loading of middleware logic. ([#13210](https://github.com/remix-run/react-router/pull/13210))
279
280 **Breaking change for `unstable_middleware` consumers**
281
282 The `route.unstable_middleware` property is no longer supported in the return value from `route.lazy`. If you want to lazily load middleware, you must use `route.unstable_lazyMiddleware`.
283
284## 7.4.0
285
286### Patch Changes
287
288- Fix root loader data on initial load redirects in SPA mode ([#13222](https://github.com/remix-run/react-router/pull/13222))
289- Load ancestor pathless/index routes in lazy route discovery for upwards non-eager-discoery routing ([#13203](https://github.com/remix-run/react-router/pull/13203))
290- Fix `shouldRevalidate` behavior for `clientLoader`-only routes in `ssr:true` apps ([#13221](https://github.com/remix-run/react-router/pull/13221))
291- UNSTABLE: Fix `RequestHandler` `loadContext` parameter type when middleware is enabled ([#13204](https://github.com/remix-run/react-router/pull/13204))
292- UNSTABLE: Update `Route.unstable_MiddlewareFunction` to have a return value of `Response | undefined` instead of `Response | void` becaue you should not return anything if you aren't returning the `Response` ([#13199](https://github.com/remix-run/react-router/pull/13199))
293- UNSTABLE(BREAKING): If a middleware throws an error, ensure we only bubble the error itself via `next()` and are no longer leaking the `MiddlewareError` implementation detail ([#13180](https://github.com/remix-run/react-router/pull/13180))
294
295## 7.3.0
296
297### Minor Changes
298
299- Add `fetcherKey` as a parameter to `patchRoutesOnNavigation` ([#13061](https://github.com/remix-run/react-router/pull/13061))
300
301 - In framework mode, Lazy Route Discovery will now detect manifest version mismatches after a new deploy
302 - On navigations to undiscovered routes, this mismatch will trigger a document reload of the destination path
303 - On `fetcher` calls to undiscovered routes, this mismatch will trigger a document reload of the current path
304
305### Patch Changes
306
307- Skip resource route flow in dev server in SPA mode ([#13113](https://github.com/remix-run/react-router/pull/13113))
308
309- Support middleware on routes (unstable) ([#12941](https://github.com/remix-run/react-router/pull/12941))
310
311 Middleware is implemented behind a `future.unstable_middleware` flag. To enable, you must enable the flag and the types in your `react-router-config.ts` file:
312
313 ```ts
314 import type { Config } from "@react-router/dev/config";
315 import type { Future } from "react-router";
316
317 declare module "react-router" {
318 interface Future {
319 unstable_middleware: true; // 👈 Enable middleware types
320 }
321 }
322
323 export default {
324 future: {
325 unstable_middleware: true, // 👈 Enable middleware
326 },
327 } satisfies Config;
328 ```
329
330 ⚠️ Middleware is unstable and should not be adopted in production. There is at least one known de-optimization in route module loading for `clientMiddleware` that we will be addressing this before a stable release.
331
332 ⚠️ Enabling middleware contains a breaking change to the `context` parameter passed to your `loader`/`action` functions - see below for more information.
333
334 Once enabled, routes can define an array of middleware functions that will run sequentially before route handlers run. These functions accept the same parameters as `loader`/`action` plus an additional `next` parameter to run the remaining data pipeline. This allows middlewares to perform logic before and after handlers execute.
335
336 ```tsx
337 // Framework mode
338 export const unstable_middleware = [serverLogger, serverAuth]; // server
339 export const unstable_clientMiddleware = [clientLogger]; // client
340
341 // Library mode
342 const routes = [
343 {
344 path: "/",
345 // Middlewares are client-side for library mode SPA's
346 unstable_middleware: [clientLogger, clientAuth],
347 loader: rootLoader,
348 Component: Root,
349 },
350 ];
351 ```
352
353 Here's a simple example of a client-side logging middleware that can be placed on the root route:
354
355 ```tsx
356 const clientLogger: Route.unstable_ClientMiddlewareFunction = async (
357 { request },
358 next
359 ) => {
360 let start = performance.now();
361
362 // Run the remaining middlewares and all route loaders
363 await next();
364
365 let duration = performance.now() - start;
366 console.log(`Navigated to ${request.url} (${duration}ms)`);
367 };
368 ```
369
370 Note that in the above example, the `next`/`middleware` functions don't return anything. This is by design as on the client there is no "response" to send over the network like there would be for middlewares running on the server. The data is all handled behind the scenes by the stateful `router`.
371
372 For a server-side middleware, the `next` function will return the HTTP `Response` that React Router will be sending across the wire, thus giving you a chance to make changes as needed. You may throw a new response to short circuit and respond immediately, or you may return a new or altered response to override the default returned by `next()`.
373
374 ```tsx
375 const serverLogger: Route.unstable_MiddlewareFunction = async (
376 { request, params, context },
377 next
378 ) => {
379 let start = performance.now();
380
381 // 👇 Grab the response here
382 let res = await next();
383
384 let duration = performance.now() - start;
385 console.log(`Navigated to ${request.url} (${duration}ms)`);
386
387 // 👇 And return it here (optional if you don't modify the response)
388 return res;
389 };
390 ```
391
392 You can throw a `redirect` from a middleware to short circuit any remaining processing:
393
394 ```tsx
395 import { sessionContext } from "../context";
396 const serverAuth: Route.unstable_MiddlewareFunction = (
397 { request, params, context },
398 next
399 ) => {
400 let session = context.get(sessionContext);
401 let user = session.get("user");
402 if (!user) {
403 session.set("returnTo", request.url);
404 throw redirect("/login", 302);
405 }
406 };
407 ```
408
409 _Note that in cases like this where you don't need to do any post-processing you don't need to call the `next` function or return a `Response`._
410
411 Here's another example of using a server middleware to detect 404s and check the CMS for a redirect:
412
413 ```tsx
414 const redirects: Route.unstable_MiddlewareFunction = async ({
415 request,
416 next,
417 }) => {
418 // attempt to handle the request
419 let res = await next();
420
421 // if it's a 404, check the CMS for a redirect, do it last
422 // because it's expensive
423 if (res.status === 404) {
424 let cmsRedirect = await checkCMSRedirects(request.url);
425 if (cmsRedirect) {
426 throw redirect(cmsRedirect, 302);
427 }
428 }
429
430 return res;
431 };
432 ```
433
434 **`context` parameter**
435
436 When middleware is enabled, your application will use a different type of `context` parameter in your loaders and actions to provide better type safety. Instead of `AppLoadContext`, `context` will now be an instance of `ContextProvider` that you can use with type-safe contexts (similar to `React.createContext`):
437
438 ```ts
439 import { unstable_createContext } from "react-router";
440 import { Route } from "./+types/root";
441 import type { Session } from "./sessions.server";
442 import { getSession } from "./sessions.server";
443
444 let sessionContext = unstable_createContext<Session>();
445
446 const sessionMiddleware: Route.unstable_MiddlewareFunction = ({
447 context,
448 request,
449 }) => {
450 let session = await getSession(request);
451 context.set(sessionContext, session);
452 // ^ must be of type Session
453 };
454
455 // ... then in some downstream middleware
456 const loggerMiddleware: Route.unstable_MiddlewareFunction = ({
457 context,
458 request,
459 }) => {
460 let session = context.get(sessionContext);
461 // ^ typeof Session
462 console.log(session.get("userId"), request.method, request.url);
463 };
464
465 // ... or some downstream loader
466 export function loader({ context }: Route.LoaderArgs) {
467 let session = context.get(sessionContext);
468 let profile = await getProfile(session.get("userId"));
469 return { profile };
470 }
471 ```
472
473 If you are using a custom server with a `getLoadContext` function, the return value for initial context values passed from the server adapter layer is no longer an object and should now return an `unstable_InitialContext` (`Map<RouterContext, unknown>`):
474
475 ```ts
476 let adapterContext = unstable_createContext<MyAdapterContext>();
477
478 function getLoadContext(req, res): unstable_InitialContext {
479 let map = new Map();
480 map.set(adapterContext, getAdapterContext(req));
481 return map;
482 }
483 ```
484
485- Fix types for loaderData and actionData that contained `Record`s ([#13139](https://github.com/remix-run/react-router/pull/13139))
486
487 UNSTABLE(BREAKING):
488
489 `unstable_SerializesTo` added a way to register custom serialization types in Single Fetch for other library and framework authors like Apollo.
490 It was implemented with branded type whose branded property that was made optional so that casting arbitrary values was easy:
491
492 ```ts
493 // without the brand being marked as optional
494 let x1 = 42 as unknown as unstable_SerializesTo<number>;
495 // ^^^^^^^^^^
496
497 // with the brand being marked as optional
498 let x2 = 42 as unstable_SerializesTo<number>;
499 ```
500
501 However, this broke type inference in `loaderData` and `actionData` for any `Record` types as those would now (incorrectly) match `unstable_SerializesTo`.
502 This affected all users, not just those that depended on `unstable_SerializesTo`.
503 To fix this, the branded property of `unstable_SerializesTo` is marked as required instead of optional.
504
505 For library and framework authors using `unstable_SerializesTo`, you may need to add `as unknown` casts before casting to `unstable_SerializesTo`.
506
507- Fix single fetch `_root.data` requests when a `basename` is used ([#12898](https://github.com/remix-run/react-router/pull/12898))
508
509- Add `context` support to client side data routers (unstable) ([#12941](https://github.com/remix-run/react-router/pull/12941))
510
511 Your application `loader` and `action` functions on the client will now receive a `context` parameter. This is an instance of `unstable_RouterContextProvider` that you use with type-safe contexts (similar to `React.createContext`) and is most useful with the corresponding `middleware`/`clientMiddleware` API's:
512
513 ```ts
514 import { unstable_createContext } from "react-router";
515
516 type User = {
517 /*...*/
518 };
519
520 let userContext = unstable_createContext<User>();
521
522 function sessionMiddleware({ context }) {
523 let user = await getUser();
524 context.set(userContext, user);
525 }
526
527 // ... then in some downstream loader
528 function loader({ context }) {
529 let user = context.get(userContext);
530 let profile = await getProfile(user.id);
531 return { profile };
532 }
533 ```
534
535 Similar to server-side requests, a fresh `context` will be created per navigation (or `fetcher` call). If you have initial data you'd like to populate in the context for every request, you can provide an `unstable_getContext` function at the root of your app:
536
537 - Library mode - `createBrowserRouter(routes, { unstable_getContext })`
538 - Framework mode - `<HydratedRouter unstable_getContext>`
539
540 This function should return an value of type `unstable_InitialContext` which is a `Map<unstable_RouterContext, unknown>` of context's and initial values:
541
542 ```ts
543 const loggerContext = unstable_createContext<(...args: unknown[]) => void>();
544
545 function logger(...args: unknown[]) {
546 console.log(new Date.toISOString(), ...args);
547 }
548
549 function unstable_getContext() {
550 let map = new Map();
551 map.set(loggerContext, logger);
552 return map;
553 }
554 ```
555
556## 7.2.0
557
558### Minor Changes
559
560- New type-safe `href` utility that guarantees links point to actual paths in your app ([#13012](https://github.com/remix-run/react-router/pull/13012))
561
562 ```tsx
563 import { href } from "react-router";
564
565 export default function Component() {
566 const link = href("/blog/:slug", { slug: "my-first-post" });
567 return (
568 <main>
569 <Link to={href("/products/:id", { id: "asdf" })} />
570 <NavLink to={href("/:lang?/about", { lang: "en" })} />
571 </main>
572 );
573 }
574 ```
575
576### Patch Changes
577
578- Fix typegen for repeated params ([#13012](https://github.com/remix-run/react-router/pull/13012))
579
580 In React Router, path parameters are keyed by their name.
581 So for a path pattern like `/a/:id/b/:id?/c/:id`, the last `:id` will set the value for `id` in `useParams` and the `params` prop.
582 For example, `/a/1/b/2/c/3` will result in the value `{ id: 3 }` at runtime.
583
584 Previously, generated types for params incorrectly modeled repeated params with an array.
585 So `/a/1/b/2/c/3` generated a type like `{ id: [1,2,3] }`.
586
587 To be consistent with runtime behavior, the generated types now correctly model the "last one wins" semantics of path parameters.
588 So `/a/1/b/2/c/3` now generates a type like `{ id: 3 }`.
589
590- Don't apply Single Fetch revalidation de-optimization when in SPA mode since there is no server HTTP request ([#12948](https://github.com/remix-run/react-router/pull/12948))
591
592- Properly handle revalidations to across a prerender/SPA boundary ([#13021](https://github.com/remix-run/react-router/pull/13021))
593
594 - In "hybrid" applications where some routes are pre-rendered and some are served from a SPA fallback, we need to avoid making `.data` requests if the path wasn't pre-rendered because the request will 404
595 - We don't know all the pre-rendered paths client-side, however:
596 - All `loader` data in `ssr:false` mode is static because it's generated at build time
597 - A route must use a `clientLoader` to do anything dynamic
598 - Therefore, if a route only has a `loader` and not a `clientLoader`, we disable revalidation by default because there is no new data to retrieve
599 - We short circuit and skip single fetch `.data` request logic if there are no server loaders with `shouldLoad=true` in our single fetch `dataStrategy`
600 - This ensures that the route doesn't cause a `.data` request that would 404 after a submission
601
602- Error at build time in `ssr:false` + `prerender` apps for the edge case scenario of: ([#13021](https://github.com/remix-run/react-router/pull/13021))
603
604 - A parent route has only a `loader` (does not have a `clientLoader`)
605 - The parent route is pre-rendered
606 - The parent route has children routes which are not prerendered
607 - This means that when the child paths are loaded via the SPA fallback, the parent won't have any `loaderData` because there is no server on which to run the `loader`
608 - This can be resolved by either adding a parent `clientLoader` or pre-rendering the child paths
609 - If you add a `clientLoader`, calling the `serverLoader()` on non-prerendered paths will throw a 404
610
611- Add unstable support for splitting route modules in framework mode via `future.unstable_splitRouteModules` ([#11871](https://github.com/remix-run/react-router/pull/11871))
612
613- Add `unstable_SerializesTo` brand type for library authors to register types serializable by React Router's streaming format (`turbo-stream`) ([`ab5b05b02`](https://github.com/remix-run/react-router/commit/ab5b05b02f99f062edb3c536c392197c88eb6c77))
614
615- Align dev server behavior with static file server behavior when `ssr:false` is set ([#12948](https://github.com/remix-run/react-router/pull/12948))
616
617 - When no `prerender` config exists, only SSR down to the root `HydrateFallback` (SPA Mode)
618 - When a `prerender` config exists but the current path is not prerendered, only SSR down to the root `HydrateFallback` (SPA Fallback)
619 - Return a 404 on `.data` requests to non-pre-rendered paths
620
621- Improve prefetch performance of CSS side effects in framework mode ([#12889](https://github.com/remix-run/react-router/pull/12889))
622
623- Disable Lazy Route Discovery for all `ssr:false` apps and not just "SPA Mode" because there is no runtime server to serve the search-param-configured `__manifest` requests ([#12894](https://github.com/remix-run/react-router/pull/12894))
624
625 - We previously only disabled this for "SPA Mode" which is `ssr:false` and no `prerender` config but we realized it should apply to all `ssr:false` apps, including those prerendering multiple pages
626 - In those `prerender` scenarios we would prerender the `/__manifest` file assuming the static file server would serve it but that makes some unneccesary assumptions about the static file server behaviors
627
628- Properly handle interrupted manifest requests in lazy route discovery ([#12915](https://github.com/remix-run/react-router/pull/12915))
629
630## 7.1.5
631
632### Patch Changes
633
634- Fix regression introduced in `7.1.4` via [#12800](https://github.com/remix-run/react-router/pull/12800) that caused issues navigating to hash routes inside splat routes for applications using Lazy Route Discovery (`patchRoutesOnNavigation`) ([#12927](https://github.com/remix-run/react-router/pull/12927))
635
636## 7.1.4
637
638### Patch Changes
639
640- Internal reorg to clean up some duplicated route module types ([#12799](https://github.com/remix-run/react-router/pull/12799))
641- Properly handle status codes that cannot have a body in single fetch responses (204, etc.) ([#12760](https://github.com/remix-run/react-router/pull/12760))
642- Stop erroring on resource routes that return raw strings/objects and instead serialize them as `text/plain` or `application/json` responses ([#12848](https://github.com/remix-run/react-router/pull/12848))
643 - This only applies when accessed as a resource route without the `.data` extension
644 - When accessed from a Single Fetch `.data` request, they will still be encoded via `turbo-stream`
645- Optimize Lazy Route Discovery path discovery to favor a single `querySelectorAll` call at the `body` level instead of many calls at the sub-tree level ([#12731](https://github.com/remix-run/react-router/pull/12731))
646- Properly bubble headers as `errorHeaders` when throwing a `data()` result ([#12846](https://github.com/remix-run/react-router/pull/12846))
647 - Avoid duplication of `Set-Cookie` headers could be duplicated if also returned from `headers`
648- Optimize route matching by skipping redundant `matchRoutes` calls when possible ([#12800](https://github.com/remix-run/react-router/pull/12800))
649
650## 7.1.3
651
652_No changes_
653
654## 7.1.2
655
656### Patch Changes
657
658- Fix issue with fetcher data cleanup in the data layer on fetcher unmount ([#12681](https://github.com/remix-run/react-router/pull/12681))
659- Do not rely on `symbol` for filtering out `redirect` responses from loader data ([#12694](https://github.com/remix-run/react-router/pull/12694))
660
661 Previously, some projects were getting type checking errors like:
662
663 ```ts
664 error TS4058: Return type of exported function has or is using name 'redirectSymbol' from external module "node_modules/..." but cannot be named.
665 ```
666
667 Now that `symbol`s are not used for the `redirect` response type, these errors should no longer be present.
668
669## 7.1.1
670
671_No changes_
672
673## 7.1.0
674
675### Patch Changes
676
677- Throw unwrapped single fetch redirect to align with pre-single fetch behavior ([#12506](https://github.com/remix-run/react-router/pull/12506))
678- Ignore redirects when inferring loader data types ([#12527](https://github.com/remix-run/react-router/pull/12527))
679- Remove `<Link prefetch>` warning which suffers from false positives in a lazy route discovery world ([#12485](https://github.com/remix-run/react-router/pull/12485))
680
681## 7.0.2
682
683### Patch Changes
684
685- temporarily only use one build in export map so packages can have a peer dependency on react router ([#12437](https://github.com/remix-run/react-router/pull/12437))
686- Generate wide `matches` and `params` types for current route and child routes ([#12397](https://github.com/remix-run/react-router/pull/12397))
687
688 At runtime, `matches` includes child route matches and `params` include child route path parameters.
689 But previously, we only generated types for parent routes in `matches`; for `params`, we only considered the parent routes and the current route.
690 To align our generated types more closely to the runtime behavior, we now generate more permissive, wider types when accessing child route information.
691
692## 7.0.1
693
694_No changes_
695
696## 7.0.0
697
698### Major Changes
699
700- Remove the original `defer` implementation in favor of using raw promises via single fetch and `turbo-stream`. This removes these exports from React Router: ([#11744](https://github.com/remix-run/react-router/pull/11744))
701
702 - `defer`
703 - `AbortedDeferredError`
704 - `type TypedDeferredData`
705 - `UNSAFE_DeferredData`
706 - `UNSAFE_DEFERRED_SYMBOL`,
707
708- - Collapse `@remix-run/router` into `react-router` ([#11505](https://github.com/remix-run/react-router/pull/11505))
709 - Collapse `react-router-dom` into `react-router`
710 - Collapse `@remix-run/server-runtime` into `react-router`
711 - Collapse `@remix-run/testing` into `react-router`
712
713- Remove single fetch future flag. ([#11522](https://github.com/remix-run/react-router/pull/11522))
714
715- Drop support for Node 16, React Router SSR now requires Node 18 or higher ([#11391](https://github.com/remix-run/react-router/pull/11391))
716
717- Remove `future.v7_startTransition` flag ([#11696](https://github.com/remix-run/react-router/pull/11696))
718
719- - Expose the underlying router promises from the following APIs for compsition in React 19 APIs: ([#11521](https://github.com/remix-run/react-router/pull/11521))
720 - `useNavigate()`
721 - `useSubmit`
722 - `useFetcher().load`
723 - `useFetcher().submit`
724 - `useRevalidator.revalidate`
725
726- Remove `future.v7_normalizeFormMethod` future flag ([#11697](https://github.com/remix-run/react-router/pull/11697))
727
728- For Remix consumers migrating to React Router, the `crypto` global from the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) is now required when using cookie and session APIs. This means that the following APIs are provided from `react-router` rather than platform-specific packages: ([#11837](https://github.com/remix-run/react-router/pull/11837))
729
730 - `createCookie`
731 - `createCookieSessionStorage`
732 - `createMemorySessionStorage`
733 - `createSessionStorage`
734
735 For consumers running older versions of Node, the `installGlobals` function from `@remix-run/node` has been updated to define `globalThis.crypto`, using [Node's `require('node:crypto').webcrypto` implementation.](https://nodejs.org/api/webcrypto.html)
736
737 Since platform-specific packages no longer need to implement this API, the following low-level APIs have been removed:
738
739 - `createCookieFactory`
740 - `createSessionStorageFactory`
741 - `createCookieSessionStorageFactory`
742 - `createMemorySessionStorageFactory`
743
744- Imports/Exports cleanup ([#11840](https://github.com/remix-run/react-router/pull/11840))
745
746 - Removed the following exports that were previously public API from `@remix-run/router`
747 - types
748 - `AgnosticDataIndexRouteObject`
749 - `AgnosticDataNonIndexRouteObject`
750 - `AgnosticDataRouteMatch`
751 - `AgnosticDataRouteObject`
752 - `AgnosticIndexRouteObject`
753 - `AgnosticNonIndexRouteObject`
754 - `AgnosticRouteMatch`
755 - `AgnosticRouteObject`
756 - `TrackedPromise`
757 - `unstable_AgnosticPatchRoutesOnMissFunction`
758 - `Action` -> exported as `NavigationType` via `react-router`
759 - `Router` exported as `DataRouter` to differentiate from RR's `<Router>`
760 - API
761 - `getToPathname` (`@private`)
762 - `joinPaths` (`@private`)
763 - `normalizePathname` (`@private`)
764 - `resolveTo` (`@private`)
765 - `stripBasename` (`@private`)
766 - `createBrowserHistory` -> in favor of `createBrowserRouter`
767 - `createHashHistory` -> in favor of `createHashRouter`
768 - `createMemoryHistory` -> in favor of `createMemoryRouter`
769 - `createRouter`
770 - `createStaticHandler` -> in favor of wrapper `createStaticHandler` in RR Dom
771 - `getStaticContextFromError`
772 - Removed the following exports that were previously public API from `react-router`
773 - `Hash`
774 - `Pathname`
775 - `Search`
776
777- update minimum node version to 18 ([#11690](https://github.com/remix-run/react-router/pull/11690))
778
779- Remove `future.v7_prependBasename` from the ionternalized `@remix-run/router` package ([#11726](https://github.com/remix-run/react-router/pull/11726))
780
781- Migrate Remix type generics to React Router ([#12180](https://github.com/remix-run/react-router/pull/12180))
782
783 - These generics are provided for Remix v2 migration purposes
784 - These generics and the APIs they exist on should be considered informally deprecated in favor of the new `Route.*` types
785 - Anyone migrating from React Router v6 should probably not leverage these new generics and should migrate straight to the `Route.*` types
786 - For React Router v6 users, these generics are new and should not impact your app, with one exception
787 - `useFetcher` previously had an optional generic (used primarily by Remix v2) that expected the data type
788 - This has been updated in v7 to expect the type of the function that generates the data (i.e., `typeof loader`/`typeof action`)
789 - Therefore, you should update your usages:
790 - `useFetcher<LoaderData>()`
791 - `useFetcher<typeof loader>()`
792
793- Remove `future.v7_throwAbortReason` from internalized `@remix-run/router` package ([#11728](https://github.com/remix-run/react-router/pull/11728))
794
795- Add `exports` field to all packages ([#11675](https://github.com/remix-run/react-router/pull/11675))
796
797- node package no longer re-exports from react-router ([#11702](https://github.com/remix-run/react-router/pull/11702))
798
799- renamed RemixContext to FrameworkContext ([#11705](https://github.com/remix-run/react-router/pull/11705))
800
801- updates the minimum React version to 18 ([#11689](https://github.com/remix-run/react-router/pull/11689))
802
803- PrefetchPageDescriptor replaced by PageLinkDescriptor ([#11960](https://github.com/remix-run/react-router/pull/11960))
804
805- - Consolidate types previously duplicated across `@remix-run/router`, `@remix-run/server-runtime`, and `@remix-run/react` now that they all live in `react-router` ([#12177](https://github.com/remix-run/react-router/pull/12177))
806 - Examples: `LoaderFunction`, `LoaderFunctionArgs`, `ActionFunction`, `ActionFunctionArgs`, `DataFunctionArgs`, `RouteManifest`, `LinksFunction`, `Route`, `EntryRoute`
807 - The `RouteManifest` type used by the "remix" code is now slightly stricter because it is using the former `@remix-run/router` `RouteManifest`
808 - `Record<string, Route> -> Record<string, Route | undefined>`
809 - Removed `AppData` type in favor of inlining `unknown` in the few locations it was used
810 - Removed `ServerRuntimeMeta*` types in favor of the `Meta*` types they were duplicated from
811
812- - Remove the `future.v7_partialHydration` flag ([#11725](https://github.com/remix-run/react-router/pull/11725))
813 - This also removes the `<RouterProvider fallbackElement>` prop
814 - To migrate, move the `fallbackElement` to a `hydrateFallbackElement`/`HydrateFallback` on your root route
815 - Also worth nothing there is a related breaking changer with this future flag:
816 - Without `future.v7_partialHydration` (when using `fallbackElement`), `state.navigation` was populated during the initial load
817 - With `future.v7_partialHydration`, `state.navigation` remains in an `"idle"` state during the initial load
818
819- Remove `v7_relativeSplatPath` future flag ([#11695](https://github.com/remix-run/react-router/pull/11695))
820
821- Drop support for Node 18, update minimum Node vestion to 20 ([#12171](https://github.com/remix-run/react-router/pull/12171))
822
823 - Remove `installGlobals()` as this should no longer be necessary
824
825- Remove remaining future flags ([#11820](https://github.com/remix-run/react-router/pull/11820))
826
827 - React Router `v7_skipActionErrorRevalidation`
828 - Remix `v3_fetcherPersist`, `v3_relativeSplatPath`, `v3_throwAbortReason`
829
830- rename createRemixStub to createRoutesStub ([#11692](https://github.com/remix-run/react-router/pull/11692))
831
832- Remove `@remix-run/router` deprecated `detectErrorBoundary` option in favor of `mapRouteProperties` ([#11751](https://github.com/remix-run/react-router/pull/11751))
833
834- Add `react-router/dom` subpath export to properly enable `react-dom` as an optional `peerDependency` ([#11851](https://github.com/remix-run/react-router/pull/11851))
835
836 - This ensures that we don't blindly `import ReactDOM from "react-dom"` in `<RouterProvider>` in order to access `ReactDOM.flushSync()`, since that would break `createMemoryRouter` use cases in non-DOM environments
837 - DOM environments should import from `react-router/dom` to get the proper component that makes `ReactDOM.flushSync()` available:
838 - If you are using the Vite plugin, use this in your `entry.client.tsx`:
839 - `import { HydratedRouter } from 'react-router/dom'`
840 - If you are not using the Vite plugin and are manually calling `createBrowserRouter`/`createHashRouter`:
841 - `import { RouterProvider } from "react-router/dom"`
842
843- Remove `future.v7_fetcherPersist` flag ([#11731](https://github.com/remix-run/react-router/pull/11731))
844
845- Update `cookie` dependency to `^1.0.1` - please see the [release notes](https://github.com/jshttp/cookie/releases) for any breaking changes ([#12172](https://github.com/remix-run/react-router/pull/12172))
846
847### Minor Changes
848
849- - Add support for `prerender` config in the React Router vite plugin, to support existing SSG use-cases ([#11539](https://github.com/remix-run/react-router/pull/11539))
850 - You can use the `prerender` config to pre-render your `.html` and `.data` files at build time and then serve them statically at runtime (either from a running server or a CDN)
851 - `prerender` can either be an array of string paths, or a function (sync or async) that returns an array of strings so that you can dynamically generate the paths by talking to your CMS, etc.
852
853 ```ts
854 // react-router.config.ts
855 import type { Config } from "@react-router/dev/config";
856
857 export default {
858 async prerender() {
859 let slugs = await fakeGetSlugsFromCms();
860 // Prerender these paths into `.html` files at build time, and `.data`
861 // files if they have loaders
862 return ["/", "/about", ...slugs.map((slug) => `/product/${slug}`)];
863 },
864 } satisfies Config;
865
866 async function fakeGetSlugsFromCms() {
867 await new Promise((r) => setTimeout(r, 1000));
868 return ["shirt", "hat"];
869 }
870 ```
871
872- Params, loader data, and action data as props for route component exports ([#11961](https://github.com/remix-run/react-router/pull/11961))
873
874 ```tsx
875 export default function Component({ params, loaderData, actionData }) {}
876
877 export function HydrateFallback({ params }) {}
878 export function ErrorBoundary({ params, loaderData, actionData }) {}
879 ```
880
881- Remove duplicate `RouterProvider` impliementations ([#11679](https://github.com/remix-run/react-router/pull/11679))
882
883- ### Typesafety improvements ([#12019](https://github.com/remix-run/react-router/pull/12019))
884
885 React Router now generates types for each of your route modules.
886 You can access those types by importing them from `./+types.<route filename without extension>`.
887 For example:
888
889 ```ts
890 // app/routes/product.tsx
891 import type * as Route from "./+types.product";
892
893 export function loader({ params }: Route.LoaderArgs) {}
894
895 export default function Component({ loaderData }: Route.ComponentProps) {}
896 ```
897
898 This initial implementation targets type inference for:
899
900 - `Params` : Path parameters from your routing config in `routes.ts` including file-based routing
901 - `LoaderData` : Loader data from `loader` and/or `clientLoader` within your route module
902 - `ActionData` : Action data from `action` and/or `clientAction` within your route module
903
904 In the future, we plan to add types for the rest of the route module exports: `meta`, `links`, `headers`, `shouldRevalidate`, etc.
905 We also plan to generate types for typesafe `Link`s:
906
907 ```tsx
908 <Link to="/products/:id" params={{ id: 1 }} />
909 // ^^^^^^^^^^^^^ ^^^^^^^^^
910 // typesafe `to` and `params` based on the available routes in your app
911 ```
912
913 Check out our docs for more:
914
915 - [_Explanations > Type Safety_](https://reactrouter.com/dev/guides/explanation/type-safety)
916 - [_How-To > Setting up type safety_](https://reactrouter.com/dev/guides/how-to/setting-up-type-safety)
917
918- Stabilize `unstable_dataStrategy` ([#11969](https://github.com/remix-run/react-router/pull/11969))
919
920- Stabilize `unstable_patchRoutesOnNavigation` ([#11970](https://github.com/remix-run/react-router/pull/11970))
921
922### Patch Changes
923
924- No changes ([`506329c4e`](https://github.com/remix-run/react-router/commit/506329c4e2e7aba9837cbfa44df6103b49423745))
925
926- chore: re-enable development warnings through a `development` exports condition. ([#12269](https://github.com/remix-run/react-router/pull/12269))
927
928- Remove unstable upload handler. ([#12015](https://github.com/remix-run/react-router/pull/12015))
929
930- Remove unneeded dependency on @web3-storage/multipart-parser ([#12274](https://github.com/remix-run/react-router/pull/12274))
931
932- Fix redirects returned from loaders/actions using `data()` ([#12021](https://github.com/remix-run/react-router/pull/12021))
933
934- fix(react-router): (v7) fix static prerender of non-ascii characters ([#12161](https://github.com/remix-run/react-router/pull/12161))
935
936- Replace `substr` with `substring` ([#12080](https://github.com/remix-run/react-router/pull/12080))
937
938- Remove the deprecated `json` utility ([#12146](https://github.com/remix-run/react-router/pull/12146))
939
940 - You can use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) if you still need to construct JSON responses in your app
941
942- Remove unneeded dependency on source-map ([#12275](https://github.com/remix-run/react-router/pull/12275))
943
944## 6.28.0
945
946### Minor Changes
947
948- - Log deprecation warnings for v7 flags ([#11750](https://github.com/remix-run/react-router/pull/11750))
949 - Add deprecation warnings to `json`/`defer` in favor of returning raw objects
950 - These methods will be removed in React Router v7
951
952### Patch Changes
953
954- Update JSDoc URLs for new website structure (add /v6/ segment) ([#12141](https://github.com/remix-run/react-router/pull/12141))
955- Updated dependencies:
956 - `@remix-run/router@1.21.0`
957
958## 6.27.0
959
960### Minor Changes
961
962- Stabilize `unstable_patchRoutesOnNavigation` ([#11973](https://github.com/remix-run/react-router/pull/11973))
963 - Add new `PatchRoutesOnNavigationFunctionArgs` type for convenience ([#11967](https://github.com/remix-run/react-router/pull/11967))
964- Stabilize `unstable_dataStrategy` ([#11974](https://github.com/remix-run/react-router/pull/11974))
965- Stabilize the `unstable_flushSync` option for navigations and fetchers ([#11989](https://github.com/remix-run/react-router/pull/11989))
966- Stabilize the `unstable_viewTransition` option for navigations and the corresponding `unstable_useViewTransitionState` hook ([#11989](https://github.com/remix-run/react-router/pull/11989))
967
968### Patch Changes
969
970- Fix bug when submitting to the current contextual route (parent route with an index child) when an `?index` param already exists from a prior submission ([#12003](https://github.com/remix-run/react-router/pull/12003))
971
972- Fix `useFormAction` bug - when removing `?index` param it would not keep other non-Remix `index` params ([#12003](https://github.com/remix-run/react-router/pull/12003))
973
974- Fix types for `RouteObject` within `PatchRoutesOnNavigationFunction`'s `patch` method so it doesn't expect agnostic route objects passed to `patch` ([#11967](https://github.com/remix-run/react-router/pull/11967))
975
976- Updated dependencies:
977 - `@remix-run/router@1.20.0`
978
979## 6.26.2
980
981### Patch Changes
982
983- Updated dependencies:
984 - `@remix-run/router@1.19.2`
985
986## 6.26.1
987
988### Patch Changes
989
990- Rename `unstable_patchRoutesOnMiss` to `unstable_patchRoutesOnNavigation` to match new behavior ([#11888](https://github.com/remix-run/react-router/pull/11888))
991- Updated dependencies:
992 - `@remix-run/router@1.19.1`
993
994## 6.26.0
995
996### Minor Changes
997
998- Add a new `replace(url, init?)` alternative to `redirect(url, init?)` that performs a `history.replaceState` instead of a `history.pushState` on client-side navigation redirects ([#11811](https://github.com/remix-run/react-router/pull/11811))
999
1000### Patch Changes
1001
1002- Fix initial hydration behavior when using `future.v7_partialHydration` along with `unstable_patchRoutesOnMiss` ([#11838](https://github.com/remix-run/react-router/pull/11838))
1003 - During initial hydration, `router.state.matches` will now include any partial matches so that we can render ancestor `HydrateFallback` components
1004- Updated dependencies:
1005 - `@remix-run/router@1.19.0`
1006
1007## 6.25.1
1008
1009No significant changes to this package were made in this release. [See the repo `CHANGELOG.md`](https://github.com/remix-run/react-router/blob/main/CHANGELOG.md) for an overview of all changes in v6.25.1.
1010
1011## 6.25.0
1012
1013### Minor Changes
1014
1015- Stabilize `future.unstable_skipActionErrorRevalidation` as `future.v7_skipActionErrorRevalidation` ([#11769](https://github.com/remix-run/react-router/pull/11769))
1016 - When this flag is enabled, actions will not automatically trigger a revalidation if they return/throw a `Response` with a `4xx`/`5xx` status code
1017 - You may still opt-into revalidation via `shouldRevalidate`
1018 - This also changes `shouldRevalidate`'s `unstable_actionStatus` parameter to `actionStatus`
1019
1020### Patch Changes
1021
1022- Fix regression and properly decode paths inside `useMatch` so matches/params reflect decoded params ([#11789](https://github.com/remix-run/react-router/pull/11789))
1023- Updated dependencies:
1024 - `@remix-run/router@1.18.0`
1025
1026## 6.24.1
1027
1028### Patch Changes
1029
1030- When using `future.v7_relativeSplatPath`, properly resolve relative paths in splat routes that are children of pathless routes ([#11633](https://github.com/remix-run/react-router/pull/11633))
1031- Updated dependencies:
1032 - `@remix-run/router@1.17.1`
1033
1034## 6.24.0
1035
1036### Minor Changes
1037
1038- Add support for Lazy Route Discovery (a.k.a. Fog of War) ([#11626](https://github.com/remix-run/react-router/pull/11626))
1039 - RFC: <https://github.com/remix-run/react-router/discussions/11113>
1040 - `unstable_patchRoutesOnMiss` docs: <https://reactrouter.com/v6/routers/create-browser-router>
1041
1042### Patch Changes
1043
1044- Updated dependencies:
1045 - `@remix-run/router@1.17.0`
1046
1047## 6.23.1
1048
1049### Patch Changes
1050
1051- allow undefined to be resolved with `<Await>` ([#11513](https://github.com/remix-run/react-router/pull/11513))
1052- Updated dependencies:
1053 - `@remix-run/router@1.16.1`
1054
1055## 6.23.0
1056
1057### Minor Changes
1058
1059- Add a new `unstable_dataStrategy` configuration option ([#11098](https://github.com/remix-run/react-router/pull/11098))
1060 - This option allows Data Router applications to take control over the approach for executing route loaders and actions
1061 - The default implementation is today's behavior, to fetch all loaders in parallel, but this option allows users to implement more advanced data flows including Remix single-fetch, middleware/context APIs, automatic loader caching, and more
1062
1063### Patch Changes
1064
1065- Updated dependencies:
1066 - `@remix-run/router@1.16.0`
1067
1068## 6.22.3
1069
1070### Patch Changes
1071
1072- Updated dependencies:
1073 - `@remix-run/router@1.15.3`
1074
1075## 6.22.2
1076
1077### Patch Changes
1078
1079- Updated dependencies:
1080 - `@remix-run/router@1.15.2`
1081
1082## 6.22.1
1083
1084### Patch Changes
1085
1086- Fix encoding/decoding issues with pre-encoded dynamic parameter values ([#11199](https://github.com/remix-run/react-router/pull/11199))
1087- Updated dependencies:
1088 - `@remix-run/router@1.15.1`
1089
1090## 6.22.0
1091
1092### Patch Changes
1093
1094- Updated dependencies:
1095 - `@remix-run/router@1.15.0`
1096
1097## 6.21.3
1098
1099### Patch Changes
1100
1101- Remove leftover `unstable_` prefix from `Blocker`/`BlockerFunction` types ([#11187](https://github.com/remix-run/react-router/pull/11187))
1102
1103## 6.21.2
1104
1105### Patch Changes
1106
1107- Updated dependencies:
1108 - `@remix-run/router@1.14.2`
1109
1110## 6.21.1
1111
1112### Patch Changes
1113
1114- Fix bug with `route.lazy` not working correctly on initial SPA load when `v7_partialHydration` is specified ([#11121](https://github.com/remix-run/react-router/pull/11121))
1115- Updated dependencies:
1116 - `@remix-run/router@1.14.1`
1117
1118## 6.21.0
1119
1120### Minor Changes
1121
1122- Add a new `future.v7_relativeSplatPath` flag to implement a breaking bug fix to relative routing when inside a splat route. ([#11087](https://github.com/remix-run/react-router/pull/11087))
1123
1124 This fix was originally added in [#10983](https://github.com/remix-run/react-router/issues/10983) and was later reverted in [#11078](https://github.com/remix-run/react-router/pull/11078) because it was determined that a large number of existing applications were relying on the buggy behavior (see [#11052](https://github.com/remix-run/react-router/issues/11052))
1125
1126 **The Bug**
1127 The buggy behavior is that without this flag, the default behavior when resolving relative paths is to _ignore_ any splat (`*`) portion of the current route path.
1128
1129 **The Background**
1130 This decision was originally made thinking that it would make the concept of nested different sections of your apps in `<Routes>` easier if relative routing would _replace_ the current splat:
1131
1132 ```jsx
1133 <BrowserRouter>
1134 <Routes>
1135 <Route path="/" element={<Home />} />
1136 <Route path="dashboard/*" element={<Dashboard />} />
1137 </Routes>
1138 </BrowserRouter>
1139 ```
1140
1141 Any paths like `/dashboard`, `/dashboard/team`, `/dashboard/projects` will match the `Dashboard` route. The dashboard component itself can then render nested `<Routes>`:
1142
1143 ```jsx
1144 function Dashboard() {
1145 return (
1146 <div>
1147 <h2>Dashboard</h2>
1148 <nav>
1149 <Link to="/">Dashboard Home</Link>
1150 <Link to="team">Team</Link>
1151 <Link to="projects">Projects</Link>
1152 </nav>
1153
1154 <Routes>
1155 <Route path="/" element={<DashboardHome />} />
1156 <Route path="team" element={<DashboardTeam />} />
1157 <Route path="projects" element={<DashboardProjects />} />
1158 </Routes>
1159 </div>
1160 );
1161 }
1162 ```
1163
1164 Now, all links and route paths are relative to the router above them. This makes code splitting and compartmentalizing your app really easy. You could render the `Dashboard` as its own independent app, or embed it into your large app without making any changes to it.
1165
1166 **The Problem**
1167
1168 The problem is that this concept of ignoring part of a path breaks a lot of other assumptions in React Router - namely that `"."` always means the current location pathname for that route. When we ignore the splat portion, we start getting invalid paths when using `"."`:
1169
1170 ```jsx
1171 // If we are on URL /dashboard/team, and we want to link to /dashboard/team:
1172 function DashboardTeam() {
1173 // ❌ This is broken and results in <a href="/dashboard">
1174 return <Link to=".">A broken link to the Current URL</Link>;
1175
1176 // ✅ This is fixed but super unintuitive since we're already at /dashboard/team!
1177 return <Link to="./team">A broken link to the Current URL</Link>;
1178 }
1179 ```
1180
1181 We've also introduced an issue that we can no longer move our `DashboardTeam` component around our route hierarchy easily - since it behaves differently if we're underneath a non-splat route, such as `/dashboard/:widget`. Now, our `"."` links will, properly point to ourself _inclusive of the dynamic param value_ so behavior will break from it's corresponding usage in a `/dashboard/*` route.
1182
1183 Even worse, consider a nested splat route configuration:
1184
1185 ```jsx
1186 <BrowserRouter>
1187 <Routes>
1188 <Route path="dashboard">
1189 <Route path="*" element={<Dashboard />} />
1190 </Route>
1191 </Routes>
1192 </BrowserRouter>
1193 ```
1194
1195 Now, a `<Link to=".">` and a `<Link to="..">` inside the `Dashboard` component go to the same place! That is definitely not correct!
1196
1197 Another common issue arose in Data Routers (and Remix) where any `<Form>` should post to it's own route `action` if you the user doesn't specify a form action:
1198
1199 ```jsx
1200 let router = createBrowserRouter({
1201 path: "/dashboard",
1202 children: [
1203 {
1204 path: "*",
1205 action: dashboardAction,
1206 Component() {
1207 // ❌ This form is broken! It throws a 405 error when it submits because
1208 // it tries to submit to /dashboard (without the splat value) and the parent
1209 // `/dashboard` route doesn't have an action
1210 return <Form method="post">...</Form>;
1211 },
1212 },
1213 ],
1214 });
1215 ```
1216
1217 This is just a compounded issue from the above because the default location for a `Form` to submit to is itself (`"."`) - and if we ignore the splat portion, that now resolves to the parent route.
1218
1219 **The Solution**
1220 If you are leveraging this behavior, it's recommended to enable the future flag, move your splat to it's own route, and leverage `../` for any links to "sibling" pages:
1221
1222 ```jsx
1223 <BrowserRouter>
1224 <Routes>
1225 <Route path="dashboard">
1226 <Route index path="*" element={<Dashboard />} />
1227 </Route>
1228 </Routes>
1229 </BrowserRouter>
1230
1231 function Dashboard() {
1232 return (
1233 <div>
1234 <h2>Dashboard</h2>
1235 <nav>
1236 <Link to="..">Dashboard Home</Link>
1237 <Link to="../team">Team</Link>
1238 <Link to="../projects">Projects</Link>
1239 </nav>
1240
1241 <Routes>
1242 <Route path="/" element={<DashboardHome />} />
1243 <Route path="team" element={<DashboardTeam />} />
1244 <Route path="projects" element={<DashboardProjects />} />
1245 </Router>
1246 </div>
1247 );
1248 }
1249 ```
1250
1251 This way, `.` means "the full current pathname for my route" in all cases (including static, dynamic, and splat routes) and `..` always means "my parents pathname".
1252
1253### Patch Changes
1254
1255- Properly handle falsy error values in ErrorBoundary's ([#11071](https://github.com/remix-run/react-router/pull/11071))
1256- Updated dependencies:
1257 - `@remix-run/router@1.14.0`
1258
1259## 6.20.1
1260
1261### Patch Changes
1262
1263- Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see <https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329>). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
1264- Updated dependencies:
1265 - `@remix-run/router@1.13.1`
1266
1267## 6.20.0
1268
1269### Minor Changes
1270
1271- Export the `PathParam` type from the public API ([#10719](https://github.com/remix-run/react-router/pull/10719))
1272
1273### Patch Changes
1274
1275- Fix bug with `resolveTo` in splat routes ([#11045](https://github.com/remix-run/react-router/pull/11045))
1276 - This is a follow up to [#10983](https://github.com/remix-run/react-router/pull/10983) to handle the few other code paths using `getPathContributingMatches`
1277 - This removes the `UNSAFE_getPathContributingMatches` export from `@remix-run/router` since we no longer need this in the `react-router`/`react-router-dom` layers
1278- Updated dependencies:
1279 - `@remix-run/router@1.13.0`
1280
1281## 6.19.0
1282
1283### Minor Changes
1284
1285- Add `unstable_flushSync` option to `useNavigate`/`useSumbit`/`fetcher.load`/`fetcher.submit` to opt-out of `React.startTransition` and into `ReactDOM.flushSync` for state updates ([#11005](https://github.com/remix-run/react-router/pull/11005))
1286- Remove the `unstable_` prefix from the [`useBlocker`](https://reactrouter.com/v6/hooks/use-blocker) hook as it's been in use for enough time that we are confident in the API. We do not plan to remove the prefix from `unstable_usePrompt` due to differences in how browsers handle `window.confirm` that prevent React Router from guaranteeing consistent/correct behavior. ([#10991](https://github.com/remix-run/react-router/pull/10991))
1287
1288### Patch Changes
1289
1290- Fix `useActionData` so it returns proper contextual action data and not _any_ action data in the tree ([#11023](https://github.com/remix-run/react-router/pull/11023))
1291
1292- Fix bug in `useResolvedPath` that would cause `useResolvedPath(".")` in a splat route to lose the splat portion of the URL path. ([#10983](https://github.com/remix-run/react-router/pull/10983))
1293
1294 - ⚠️ This fixes a quite long-standing bug specifically for `"."` paths inside a splat route which incorrectly dropped the splat portion of the URL. If you are relative routing via `"."` inside a splat route in your application you should double check that your logic is not relying on this buggy behavior and update accordingly.
1295
1296- Updated dependencies:
1297 - `@remix-run/router@1.12.0`
1298
1299## 6.18.0
1300
1301### Patch Changes
1302
1303- Fix the `future` prop on `BrowserRouter`, `HashRouter` and `MemoryRouter` so that it accepts a `Partial<FutureConfig>` instead of requiring all flags to be included. ([#10962](https://github.com/remix-run/react-router/pull/10962))
1304- Updated dependencies:
1305 - `@remix-run/router@1.11.0`
1306
1307## 6.17.0
1308
1309### Patch Changes
1310
1311- Fix `RouterProvider` `future` prop type to be a `Partial<FutureConfig>` so that not all flags must be specified ([#10900](https://github.com/remix-run/react-router/pull/10900))
1312- Updated dependencies:
1313 - `@remix-run/router@1.10.0`
1314
1315## 6.16.0
1316
1317### Minor Changes
1318
1319- In order to move towards stricter TypeScript support in the future, we're aiming to replace current usages of `any` with `unknown` on exposed typings for user-provided data. To do this in Remix v2 without introducing breaking changes in React Router v6, we have added generics to a number of shared types. These continue to default to `any` in React Router and are overridden with `unknown` in Remix. In React Router v7 we plan to move these to `unknown` as a breaking change. ([#10843](https://github.com/remix-run/react-router/pull/10843))
1320 - `Location` now accepts a generic for the `location.state` value
1321 - `ActionFunctionArgs`/`ActionFunction`/`LoaderFunctionArgs`/`LoaderFunction` now accept a generic for the `context` parameter (only used in SSR usages via `createStaticHandler`)
1322 - The return type of `useMatches` (now exported as `UIMatch`) accepts generics for `match.data` and `match.handle` - both of which were already set to `unknown`
1323- Move the `@private` class export `ErrorResponse` to an `UNSAFE_ErrorResponseImpl` export since it is an implementation detail and there should be no construction of `ErrorResponse` instances in userland. This frees us up to export a `type ErrorResponse` which correlates to an instance of the class via `InstanceType`. Userland code should only ever be using `ErrorResponse` as a type and should be type-narrowing via `isRouteErrorResponse`. ([#10811](https://github.com/remix-run/react-router/pull/10811))
1324- Export `ShouldRevalidateFunctionArgs` interface ([#10797](https://github.com/remix-run/react-router/pull/10797))
1325- Removed private/internal APIs only required for the Remix v1 backwards compatibility layer and no longer needed in Remix v2 (`_isFetchActionRedirect`, `_hasFetcherDoneAnything`) ([#10715](https://github.com/remix-run/react-router/pull/10715))
1326
1327### Patch Changes
1328
1329- Updated dependencies:
1330 - `@remix-run/router@1.9.0`
1331
1332## 6.15.0
1333
1334### Minor Changes
1335
1336- Add's a new `redirectDocument()` function which allows users to specify that a redirect from a `loader`/`action` should trigger a document reload (via `window.location`) instead of attempting to navigate to the redirected location via React Router ([#10705](https://github.com/remix-run/react-router/pull/10705))
1337
1338### Patch Changes
1339
1340- Ensure `useRevalidator` is referentially stable across re-renders if revalidations are not actively occurring ([#10707](https://github.com/remix-run/react-router/pull/10707))
1341- Updated dependencies:
1342 - `@remix-run/router@1.8.0`
1343
1344## 6.14.2
1345
1346### Patch Changes
1347
1348- Updated dependencies:
1349 - `@remix-run/router@1.7.2`
1350
1351## 6.14.1
1352
1353### Patch Changes
1354
1355- Fix loop in `unstable_useBlocker` when used with an unstable blocker function ([#10652](https://github.com/remix-run/react-router/pull/10652))
1356- Fix issues with reused blockers on subsequent navigations ([#10656](https://github.com/remix-run/react-router/pull/10656))
1357- Updated dependencies:
1358 - `@remix-run/router@1.7.1`
1359
1360## 6.14.0
1361
1362### Patch Changes
1363
1364- Strip `basename` from locations provided to `unstable_useBlocker` functions to match `useLocation` ([#10573](https://github.com/remix-run/react-router/pull/10573))
1365- Fix `generatePath` when passed a numeric `0` value parameter ([#10612](https://github.com/remix-run/react-router/pull/10612))
1366- Fix `unstable_useBlocker` key issues in `StrictMode` ([#10573](https://github.com/remix-run/react-router/pull/10573))
1367- Fix `tsc --skipLibCheck:false` issues on React 17 ([#10622](https://github.com/remix-run/react-router/pull/10622))
1368- Upgrade `typescript` to 5.1 ([#10581](https://github.com/remix-run/react-router/pull/10581))
1369- Updated dependencies:
1370 - `@remix-run/router@1.7.0`
1371
1372## 6.13.0
1373
1374### Minor Changes
1375
1376- Move [`React.startTransition`](https://react.dev/reference/react/startTransition) usage behind a [future flag](https://reactrouter.com/v6/guides/api-development-strategy) to avoid issues with existing incompatible `Suspense` usages. We recommend folks adopting this flag to be better compatible with React concurrent mode, but if you run into issues you can continue without the use of `startTransition` until v7. Issues usually boils down to creating net-new promises during the render cycle, so if you run into issues you should either lift your promise creation out of the render cycle or put it behind a `useMemo`. ([#10596](https://github.com/remix-run/react-router/pull/10596))
1377
1378 Existing behavior will no longer include `React.startTransition`:
1379
1380 ```jsx
1381 <BrowserRouter>
1382 <Routes>{/*...*/}</Routes>
1383 </BrowserRouter>
1384
1385 <RouterProvider router={router} />
1386 ```
1387
1388 If you wish to enable `React.startTransition`, pass the future flag to your component:
1389
1390 ```jsx
1391 <BrowserRouter future={{ v7_startTransition: true }}>
1392 <Routes>{/*...*/}</Routes>
1393 </BrowserRouter>
1394
1395 <RouterProvider router={router} future={{ v7_startTransition: true }}/>
1396 ```
1397
1398### Patch Changes
1399
1400- Work around webpack/terser `React.startTransition` minification bug in production mode ([#10588](https://github.com/remix-run/react-router/pull/10588))
1401
1402## 6.12.1
1403
1404> \[!WARNING]
1405> Please use version `6.13.0` or later instead of `6.12.1`. This version suffers from a `webpack`/`terser` minification issue resulting in invalid minified code in your resulting production bundles which can cause issues in your application. See [#10579](https://github.com/remix-run/react-router/issues/10579) for more details.
1406
1407### Patch Changes
1408
1409- Adjust feature detection of `React.startTransition` to fix webpack + react 17 compilation error ([#10569](https://github.com/remix-run/react-router/pull/10569))
1410
1411## 6.12.0
1412
1413### Minor Changes
1414
1415- Wrap internal router state updates with `React.startTransition` if it exists ([#10438](https://github.com/remix-run/react-router/pull/10438))
1416
1417### Patch Changes
1418
1419- Updated dependencies:
1420 - `@remix-run/router@1.6.3`
1421
1422## 6.11.2
1423
1424### Patch Changes
1425
1426- Fix `basename` duplication in descendant `<Routes>` inside a `<RouterProvider>` ([#10492](https://github.com/remix-run/react-router/pull/10492))
1427- Updated dependencies:
1428 - `@remix-run/router@1.6.2`
1429
1430## 6.11.1
1431
1432### Patch Changes
1433
1434- Fix usage of `Component` API within descendant `<Routes>` ([#10434](https://github.com/remix-run/react-router/pull/10434))
1435- Fix bug when calling `useNavigate` from `<Routes>` inside a `<RouterProvider>` ([#10432](https://github.com/remix-run/react-router/pull/10432))
1436- Fix usage of `<Navigate>` in strict mode when using a data router ([#10435](https://github.com/remix-run/react-router/pull/10435))
1437- Updated dependencies:
1438 - `@remix-run/router@1.6.1`
1439
1440## 6.11.0
1441
1442### Patch Changes
1443
1444- Log loader/action errors to the console in dev for easier stack trace evaluation ([#10286](https://github.com/remix-run/react-router/pull/10286))
1445- Fix bug preventing rendering of descendant `<Routes>` when `RouterProvider` errors existed ([#10374](https://github.com/remix-run/react-router/pull/10374))
1446- Fix inadvertent re-renders when using `Component` instead of `element` on a route definition ([#10287](https://github.com/remix-run/react-router/pull/10287))
1447- Fix detection of `useNavigate` in the render cycle by setting the `activeRef` in a layout effect, allowing the `navigate` function to be passed to child components and called in a `useEffect` there. ([#10394](https://github.com/remix-run/react-router/pull/10394))
1448- Switched from `useSyncExternalStore` to `useState` for internal `@remix-run/router` router state syncing in `<RouterProvider>`. We found some [subtle bugs](https://codesandbox.io/s/use-sync-external-store-loop-9g7b81) where router state updates got propagated _before_ other normal `useState` updates, which could lead to footguns in `useEffect` calls. ([#10377](https://github.com/remix-run/react-router/pull/10377), [#10409](https://github.com/remix-run/react-router/pull/10409))
1449- Allow `useRevalidator()` to resolve a loader-driven error boundary scenario ([#10369](https://github.com/remix-run/react-router/pull/10369))
1450- Avoid unnecessary unsubscribe/resubscribes on router state changes ([#10409](https://github.com/remix-run/react-router/pull/10409))
1451- When using a `RouterProvider`, `useNavigate`/`useSubmit`/`fetcher.submit` are now stable across location changes, since we can handle relative routing via the `@remix-run/router` instance and get rid of our dependence on `useLocation()`. When using `BrowserRouter`, these hooks remain unstable across location changes because they still rely on `useLocation()`. ([#10336](https://github.com/remix-run/react-router/pull/10336))
1452- Updated dependencies:
1453 - `@remix-run/router@1.6.0`
1454
1455## 6.10.0
1456
1457### Minor Changes
1458
1459- Added support for [**Future Flags**](https://reactrouter.com/v6/guides/api-development-strategy) in React Router. The first flag being introduced is `future.v7_normalizeFormMethod` which will normalize the exposed `useNavigation()/useFetcher()` `formMethod` fields as uppercase HTTP methods to align with the `fetch()` behavior. ([#10207](https://github.com/remix-run/react-router/pull/10207))
1460
1461 - When `future.v7_normalizeFormMethod === false` (default v6 behavior),
1462 - `useNavigation().formMethod` is lowercase
1463 - `useFetcher().formMethod` is lowercase
1464 - When `future.v7_normalizeFormMethod === true`:
1465 - `useNavigation().formMethod` is uppercase
1466 - `useFetcher().formMethod` is uppercase
1467
1468### Patch Changes
1469
1470- Fix route ID generation when using Fragments in `createRoutesFromElements` ([#10193](https://github.com/remix-run/react-router/pull/10193))
1471- Updated dependencies:
1472 - `@remix-run/router@1.5.0`
1473
1474## 6.9.0
1475
1476### Minor Changes
1477
1478- React Router now supports an alternative way to define your route `element` and `errorElement` fields as React Components instead of React Elements. You can instead pass a React Component to the new `Component` and `ErrorBoundary` fields if you choose. There is no functional difference between the two, so use whichever approach you prefer 😀. You shouldn't be defining both, but if you do `Component`/`ErrorBoundary` will "win". ([#10045](https://github.com/remix-run/react-router/pull/10045))
1479
1480 **Example JSON Syntax**
1481
1482 ```jsx
1483 // Both of these work the same:
1484 const elementRoutes = [{
1485 path: '/',
1486 element: <Home />,
1487 errorElement: <HomeError />,
1488 }]
1489
1490 const componentRoutes = [{
1491 path: '/',
1492 Component: Home,
1493 ErrorBoundary: HomeError,
1494 }]
1495
1496 function Home() { ... }
1497 function HomeError() { ... }
1498 ```
1499
1500 **Example JSX Syntax**
1501
1502 ```jsx
1503 // Both of these work the same:
1504 const elementRoutes = createRoutesFromElements(
1505 <Route path='/' element={<Home />} errorElement={<HomeError /> } />
1506 );
1507
1508 const componentRoutes = createRoutesFromElements(
1509 <Route path='/' Component={Home} ErrorBoundary={HomeError} />
1510 );
1511
1512 function Home() { ... }
1513 function HomeError() { ... }
1514 ```
1515
1516- **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045))
1517
1518 In order to keep your application bundles small and support code-splitting of your routes, we've introduced a new `lazy()` route property. This is an async function that resolves the non-route-matching portions of your route definition (`loader`, `action`, `element`/`Component`, `errorElement`/`ErrorBoundary`, `shouldRevalidate`, `handle`).
1519
1520 Lazy routes are resolved on initial load and during the `loading` or `submitting` phase of a navigation or fetcher call. You cannot lazily define route-matching properties (`path`, `index`, `children`) since we only execute your lazy route functions after we've matched known routes.
1521
1522 Your `lazy` functions will typically return the result of a dynamic import.
1523
1524 ```jsx
1525 // In this example, we assume most folks land on the homepage so we include that
1526 // in our critical-path bundle, but then we lazily load modules for /a and /b so
1527 // they don't load until the user navigates to those routes
1528 let routes = createRoutesFromElements(
1529 <Route path="/" element={<Layout />}>
1530 <Route index element={<Home />} />
1531 <Route path="a" lazy={() => import("./a")} />
1532 <Route path="b" lazy={() => import("./b")} />
1533 </Route>
1534 );
1535 ```
1536
1537 Then in your lazy route modules, export the properties you want defined for the route:
1538
1539 ```jsx
1540 export async function loader({ request }) {
1541 let data = await fetchData(request);
1542 return json(data);
1543 }
1544
1545 // Export a `Component` directly instead of needing to create a React Element from it
1546 export function Component() {
1547 let data = useLoaderData();
1548
1549 return (
1550 <>
1551 <h1>You made it!</h1>
1552 <p>{data}</p>
1553 </>
1554 );
1555 }
1556
1557 // Export an `ErrorBoundary` directly instead of needing to create a React Element from it
1558 export function ErrorBoundary() {
1559 let error = useRouteError();
1560 return isRouteErrorResponse(error) ? (
1561 <h1>
1562 {error.status} {error.statusText}
1563 </h1>
1564 ) : (
1565 <h1>{error.message || error}</h1>
1566 );
1567 }
1568 ```
1569
1570 An example of this in action can be found in the [`examples/lazy-loading-router-provider`](https://github.com/remix-run/react-router/tree/main/examples/lazy-loading-router-provider) directory of the repository.
1571
1572 🙌 Huge thanks to @rossipedia for the [Initial Proposal](https://github.com/remix-run/react-router/discussions/9826) and [POC Implementation](https://github.com/remix-run/react-router/pull/9830).
1573
1574- Updated dependencies:
1575 - `@remix-run/router@1.4.0`
1576
1577### Patch Changes
1578
1579- Fix `generatePath` incorrectly applying parameters in some cases ([#10078](https://github.com/remix-run/react-router/pull/10078))
1580- Improve memoization for context providers to avoid unnecessary re-renders ([#9983](https://github.com/remix-run/react-router/pull/9983))
1581
1582## 6.8.2
1583
1584### Patch Changes
1585
1586- Updated dependencies:
1587 - `@remix-run/router@1.3.3`
1588
1589## 6.8.1
1590
1591### Patch Changes
1592
1593- Remove inaccurate console warning for POP navigations and update active blocker logic ([#10030](https://github.com/remix-run/react-router/pull/10030))
1594- Updated dependencies:
1595 - `@remix-run/router@1.3.2`
1596
1597## 6.8.0
1598
1599### Patch Changes
1600
1601- Updated dependencies:
1602 - `@remix-run/router@1.3.1`
1603
1604## 6.7.0
1605
1606### Minor Changes
1607
1608- Add `unstable_useBlocker` hook for blocking navigations within the app's location origin ([#9709](https://github.com/remix-run/react-router/pull/9709))
1609
1610### Patch Changes
1611
1612- Fix `generatePath` when optional params are present ([#9764](https://github.com/remix-run/react-router/pull/9764))
1613- Update `<Await>` to accept `ReactNode` as children function return result ([#9896](https://github.com/remix-run/react-router/pull/9896))
1614- Updated dependencies:
1615 - `@remix-run/router@1.3.0`
1616
1617## 6.6.2
1618
1619### Patch Changes
1620
1621- Ensure `useId` consistency during SSR ([#9805](https://github.com/remix-run/react-router/pull/9805))
1622
1623## 6.6.1
1624
1625### Patch Changes
1626
1627- Updated dependencies:
1628 - `@remix-run/router@1.2.1`
1629
1630## 6.6.0
1631
1632### Patch Changes
1633
1634- Prevent `useLoaderData` usage in `errorElement` ([#9735](https://github.com/remix-run/react-router/pull/9735))
1635- Updated dependencies:
1636 - `@remix-run/router@1.2.0`
1637
1638## 6.5.0
1639
1640This release introduces support for [Optional Route Segments](https://github.com/remix-run/react-router/issues/9546). Now, adding a `?` to the end of any path segment will make that entire segment optional. This works for both static segments and dynamic parameters.
1641
1642**Optional Params Examples**
1643
1644- `<Route path=":lang?/about>` will match:
1645 - `/:lang/about`
1646 - `/about`
1647- `<Route path="/multistep/:widget1?/widget2?/widget3?">` will match:
1648 - `/multistep`
1649 - `/multistep/:widget1`
1650 - `/multistep/:widget1/:widget2`
1651 - `/multistep/:widget1/:widget2/:widget3`
1652
1653**Optional Static Segment Example**
1654
1655- `<Route path="/home?">` will match:
1656 - `/`
1657 - `/home`
1658- `<Route path="/fr?/about">` will match:
1659 - `/about`
1660 - `/fr/about`
1661
1662### Minor Changes
1663
1664- Allows optional routes and optional static segments ([#9650](https://github.com/remix-run/react-router/pull/9650))
1665
1666### Patch Changes
1667
1668- Stop incorrectly matching on partial named parameters, i.e. `<Route path="prefix-:param">`, to align with how splat parameters work. If you were previously relying on this behavior then it's recommended to extract the static portion of the path at the `useParams` call site: ([#9506](https://github.com/remix-run/react-router/pull/9506))
1669
1670```jsx
1671// Old behavior at URL /prefix-123
1672<Route path="prefix-:id" element={<Comp /> }>
1673
1674function Comp() {
1675 let params = useParams(); // { id: '123' }
1676 let id = params.id; // "123"
1677 ...
1678}
1679
1680// New behavior at URL /prefix-123
1681<Route path=":id" element={<Comp /> }>
1682
1683function Comp() {
1684 let params = useParams(); // { id: 'prefix-123' }
1685 let id = params.id.replace(/^prefix-/, ''); // "123"
1686 ...
1687}
1688```
1689
1690- Updated dependencies:
1691 - `@remix-run/router@1.1.0`
1692
1693## 6.4.5
1694
1695### Patch Changes
1696
1697- Updated dependencies:
1698 - `@remix-run/router@1.0.5`
1699
1700## 6.4.4
1701
1702### Patch Changes
1703
1704- Updated dependencies:
1705 - `@remix-run/router@1.0.4`
1706
1707## 6.4.3
1708
1709### Patch Changes
1710
1711- `useRoutes` should be able to return `null` when passing `locationArg` ([#9485](https://github.com/remix-run/react-router/pull/9485))
1712- fix `initialEntries` type in `createMemoryRouter` ([#9498](https://github.com/remix-run/react-router/pull/9498))
1713- Updated dependencies:
1714 - `@remix-run/router@1.0.3`
1715
1716## 6.4.2
1717
1718### Patch Changes
1719
1720- Fix `IndexRouteObject` and `NonIndexRouteObject` types to make `hasErrorElement` optional ([#9394](https://github.com/remix-run/react-router/pull/9394))
1721- Enhance console error messages for invalid usage of data router hooks ([#9311](https://github.com/remix-run/react-router/pull/9311))
1722- If an index route has children, it will result in a runtime error. We have strengthened our `RouteObject`/`RouteProps` types to surface the error in TypeScript. ([#9366](https://github.com/remix-run/react-router/pull/9366))
1723- Updated dependencies:
1724 - `@remix-run/router@1.0.2`
1725
1726## 6.4.1
1727
1728### Patch Changes
1729
1730- Preserve state from `initialEntries` ([#9288](https://github.com/remix-run/react-router/pull/9288))
1731- Updated dependencies:
1732 - `@remix-run/router@1.0.1`
1733
1734## 6.4.0
1735
1736Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs over from Remix. Here's a quick high level overview, but it's recommended you go check out the [docs](https://reactrouter.com), especially the [feature overview](https://reactrouter.com/en/6.4.0/start/overview) and the [tutorial](https://reactrouter.com/en/6.4.0/start/tutorial).
1737
1738**New APIs**
1739
1740- Create your router with `createMemoryRouter`
1741- Render your router with `<RouterProvider>`
1742- Load data with a Route `loader` and mutate with a Route `action`
1743- Handle errors with Route `errorElement`
1744- Defer non-critical data with `defer` and `Await`
1745
1746**Bug Fixes**
1747
1748- Path resolution is now trailing slash agnostic (#8861)
1749- `useLocation` returns the scoped location inside a `<Routes location>` component (#9094)
1750
1751**Updated Dependencies**
1752
1753- `@remix-run/router@1.0.0`