UNPKG

34 kBMarkdownView Raw
1# `react-router`
2
3## 6.28.0
4
5### Minor Changes
6
7- - Log deprecation warnings for v7 flags ([#11750](https://github.com/remix-run/react-router/pull/11750))
8 - Add deprecation warnings to `json`/`defer` in favor of returning raw objects
9 - These methods will be removed in React Router v7
10
11### Patch Changes
12
13- Update JSDoc URLs for new website structure (add /v6/ segment) ([#12141](https://github.com/remix-run/react-router/pull/12141))
14- Updated dependencies:
15 - `@remix-run/router@1.21.0`
16
17## 6.27.0
18
19### Minor Changes
20
21- Stabilize `unstable_patchRoutesOnNavigation` ([#11973](https://github.com/remix-run/react-router/pull/11973))
22 - Add new `PatchRoutesOnNavigationFunctionArgs` type for convenience ([#11967](https://github.com/remix-run/react-router/pull/11967))
23- Stabilize `unstable_dataStrategy` ([#11974](https://github.com/remix-run/react-router/pull/11974))
24- Stabilize the `unstable_flushSync` option for navigations and fetchers ([#11989](https://github.com/remix-run/react-router/pull/11989))
25- Stabilize the `unstable_viewTransition` option for navigations and the corresponding `unstable_useViewTransitionState` hook ([#11989](https://github.com/remix-run/react-router/pull/11989))
26
27### Patch Changes
28
29- 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))
30
31- 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))
32
33- 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))
34
35- Updated dependencies:
36 - `@remix-run/router@1.20.0`
37
38## 6.26.2
39
40### Patch Changes
41
42- Updated dependencies:
43 - `@remix-run/router@1.19.2`
44
45## 6.26.1
46
47### Patch Changes
48
49- Rename `unstable_patchRoutesOnMiss` to `unstable_patchRoutesOnNavigation` to match new behavior ([#11888](https://github.com/remix-run/react-router/pull/11888))
50- Updated dependencies:
51 - `@remix-run/router@1.19.1`
52
53## 6.26.0
54
55### Minor Changes
56
57- 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))
58
59### Patch Changes
60
61- Fix initial hydration behavior when using `future.v7_partialHydration` along with `unstable_patchRoutesOnMiss` ([#11838](https://github.com/remix-run/react-router/pull/11838))
62 - During initial hydration, `router.state.matches` will now include any partial matches so that we can render ancestor `HydrateFallback` components
63- Updated dependencies:
64 - `@remix-run/router@1.19.0`
65
66## 6.25.1
67
68No 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.
69
70## 6.25.0
71
72### Minor Changes
73
74- Stabilize `future.unstable_skipActionErrorRevalidation` as `future.v7_skipActionErrorRevalidation` ([#11769](https://github.com/remix-run/react-router/pull/11769))
75 - When this flag is enabled, actions will not automatically trigger a revalidation if they return/throw a `Response` with a `4xx`/`5xx` status code
76 - You may still opt-into revalidation via `shouldRevalidate`
77 - This also changes `shouldRevalidate`'s `unstable_actionStatus` parameter to `actionStatus`
78
79### Patch Changes
80
81- Fix regression and properly decode paths inside `useMatch` so matches/params reflect decoded params ([#11789](https://github.com/remix-run/react-router/pull/11789))
82- Updated dependencies:
83 - `@remix-run/router@1.18.0`
84
85## 6.24.1
86
87### Patch Changes
88
89- 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))
90- Updated dependencies:
91 - `@remix-run/router@1.17.1`
92
93## 6.24.0
94
95### Minor Changes
96
97- Add support for Lazy Route Discovery (a.k.a. Fog of War) ([#11626](https://github.com/remix-run/react-router/pull/11626))
98 - RFC: <https://github.com/remix-run/react-router/discussions/11113>
99 - `unstable_patchRoutesOnMiss` docs: <https://reactrouter.com/v6/routers/create-browser-router>
100
101### Patch Changes
102
103- Updated dependencies:
104 - `@remix-run/router@1.17.0`
105
106## 6.23.1
107
108### Patch Changes
109
110- allow undefined to be resolved with `<Await>` ([#11513](https://github.com/remix-run/react-router/pull/11513))
111- Updated dependencies:
112 - `@remix-run/router@1.16.1`
113
114## 6.23.0
115
116### Minor Changes
117
118- Add a new `unstable_dataStrategy` configuration option ([#11098](https://github.com/remix-run/react-router/pull/11098))
119 - This option allows Data Router applications to take control over the approach for executing route loaders and actions
120 - 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
121
122### Patch Changes
123
124- Updated dependencies:
125 - `@remix-run/router@1.16.0`
126
127## 6.22.3
128
129### Patch Changes
130
131- Updated dependencies:
132 - `@remix-run/router@1.15.3`
133
134## 6.22.2
135
136### Patch Changes
137
138- Updated dependencies:
139 - `@remix-run/router@1.15.2`
140
141## 6.22.1
142
143### Patch Changes
144
145- Fix encoding/decoding issues with pre-encoded dynamic parameter values ([#11199](https://github.com/remix-run/react-router/pull/11199))
146- Updated dependencies:
147 - `@remix-run/router@1.15.1`
148
149## 6.22.0
150
151### Patch Changes
152
153- Updated dependencies:
154 - `@remix-run/router@1.15.0`
155
156## 6.21.3
157
158### Patch Changes
159
160- Remove leftover `unstable_` prefix from `Blocker`/`BlockerFunction` types ([#11187](https://github.com/remix-run/react-router/pull/11187))
161
162## 6.21.2
163
164### Patch Changes
165
166- Updated dependencies:
167 - `@remix-run/router@1.14.2`
168
169## 6.21.1
170
171### Patch Changes
172
173- 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))
174- Updated dependencies:
175 - `@remix-run/router@1.14.1`
176
177## 6.21.0
178
179### Minor Changes
180
181- 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))
182
183 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))
184
185 **The Bug**
186 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.
187
188 **The Background**
189 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:
190
191 ```jsx
192 <BrowserRouter>
193 <Routes>
194 <Route path="/" element={<Home />} />
195 <Route path="dashboard/*" element={<Dashboard />} />
196 </Routes>
197 </BrowserRouter>
198 ```
199
200 Any paths like `/dashboard`, `/dashboard/team`, `/dashboard/projects` will match the `Dashboard` route. The dashboard component itself can then render nested `<Routes>`:
201
202 ```jsx
203 function Dashboard() {
204 return (
205 <div>
206 <h2>Dashboard</h2>
207 <nav>
208 <Link to="/">Dashboard Home</Link>
209 <Link to="team">Team</Link>
210 <Link to="projects">Projects</Link>
211 </nav>
212
213 <Routes>
214 <Route path="/" element={<DashboardHome />} />
215 <Route path="team" element={<DashboardTeam />} />
216 <Route path="projects" element={<DashboardProjects />} />
217 </Routes>
218 </div>
219 );
220 }
221 ```
222
223 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.
224
225 **The Problem**
226
227 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 `"."`:
228
229 ```jsx
230 // If we are on URL /dashboard/team, and we want to link to /dashboard/team:
231 function DashboardTeam() {
232 // ❌ This is broken and results in <a href="/dashboard">
233 return <Link to=".">A broken link to the Current URL</Link>;
234
235 // ✅ This is fixed but super unintuitive since we're already at /dashboard/team!
236 return <Link to="./team">A broken link to the Current URL</Link>;
237 }
238 ```
239
240 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.
241
242 Even worse, consider a nested splat route configuration:
243
244 ```jsx
245 <BrowserRouter>
246 <Routes>
247 <Route path="dashboard">
248 <Route path="*" element={<Dashboard />} />
249 </Route>
250 </Routes>
251 </BrowserRouter>
252 ```
253
254 Now, a `<Link to=".">` and a `<Link to="..">` inside the `Dashboard` component go to the same place! That is definitely not correct!
255
256 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:
257
258 ```jsx
259 let router = createBrowserRouter({
260 path: "/dashboard",
261 children: [
262 {
263 path: "*",
264 action: dashboardAction,
265 Component() {
266 // ❌ This form is broken! It throws a 405 error when it submits because
267 // it tries to submit to /dashboard (without the splat value) and the parent
268 // `/dashboard` route doesn't have an action
269 return <Form method="post">...</Form>;
270 },
271 },
272 ],
273 });
274 ```
275
276 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.
277
278 **The Solution**
279 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:
280
281 ```jsx
282 <BrowserRouter>
283 <Routes>
284 <Route path="dashboard">
285 <Route index path="*" element={<Dashboard />} />
286 </Route>
287 </Routes>
288 </BrowserRouter>
289
290 function Dashboard() {
291 return (
292 <div>
293 <h2>Dashboard</h2>
294 <nav>
295 <Link to="..">Dashboard Home</Link>
296 <Link to="../team">Team</Link>
297 <Link to="../projects">Projects</Link>
298 </nav>
299
300 <Routes>
301 <Route path="/" element={<DashboardHome />} />
302 <Route path="team" element={<DashboardTeam />} />
303 <Route path="projects" element={<DashboardProjects />} />
304 </Router>
305 </div>
306 );
307 }
308 ```
309
310 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".
311
312### Patch Changes
313
314- Properly handle falsy error values in ErrorBoundary's ([#11071](https://github.com/remix-run/react-router/pull/11071))
315- Updated dependencies:
316 - `@remix-run/router@1.14.0`
317
318## 6.20.1
319
320### Patch Changes
321
322- 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))
323- Updated dependencies:
324 - `@remix-run/router@1.13.1`
325
326## 6.20.0
327
328### Minor Changes
329
330- Export the `PathParam` type from the public API ([#10719](https://github.com/remix-run/react-router/pull/10719))
331
332### Patch Changes
333
334- Fix bug with `resolveTo` in splat routes ([#11045](https://github.com/remix-run/react-router/pull/11045))
335 - 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`
336 - This removes the `UNSAFE_getPathContributingMatches` export from `@remix-run/router` since we no longer need this in the `react-router`/`react-router-dom` layers
337- Updated dependencies:
338 - `@remix-run/router@1.13.0`
339
340## 6.19.0
341
342### Minor Changes
343
344- 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))
345- 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))
346
347### Patch Changes
348
349- 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))
350
351- 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))
352
353 - ⚠️ 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.
354
355- Updated dependencies:
356 - `@remix-run/router@1.12.0`
357
358## 6.18.0
359
360### Patch Changes
361
362- 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))
363- Updated dependencies:
364 - `@remix-run/router@1.11.0`
365
366## 6.17.0
367
368### Patch Changes
369
370- 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))
371- Updated dependencies:
372 - `@remix-run/router@1.10.0`
373
374## 6.16.0
375
376### Minor Changes
377
378- 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))
379 - `Location` now accepts a generic for the `location.state` value
380 - `ActionFunctionArgs`/`ActionFunction`/`LoaderFunctionArgs`/`LoaderFunction` now accept a generic for the `context` parameter (only used in SSR usages via `createStaticHandler`)
381 - 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`
382- 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))
383- Export `ShouldRevalidateFunctionArgs` interface ([#10797](https://github.com/remix-run/react-router/pull/10797))
384- 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))
385
386### Patch Changes
387
388- Updated dependencies:
389 - `@remix-run/router@1.9.0`
390
391## 6.15.0
392
393### Minor Changes
394
395- 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))
396
397### Patch Changes
398
399- Ensure `useRevalidator` is referentially stable across re-renders if revalidations are not actively occurring ([#10707](https://github.com/remix-run/react-router/pull/10707))
400- Updated dependencies:
401 - `@remix-run/router@1.8.0`
402
403## 6.14.2
404
405### Patch Changes
406
407- Updated dependencies:
408 - `@remix-run/router@1.7.2`
409
410## 6.14.1
411
412### Patch Changes
413
414- Fix loop in `unstable_useBlocker` when used with an unstable blocker function ([#10652](https://github.com/remix-run/react-router/pull/10652))
415- Fix issues with reused blockers on subsequent navigations ([#10656](https://github.com/remix-run/react-router/pull/10656))
416- Updated dependencies:
417 - `@remix-run/router@1.7.1`
418
419## 6.14.0
420
421### Patch Changes
422
423- Strip `basename` from locations provided to `unstable_useBlocker` functions to match `useLocation` ([#10573](https://github.com/remix-run/react-router/pull/10573))
424- Fix `generatePath` when passed a numeric `0` value parameter ([#10612](https://github.com/remix-run/react-router/pull/10612))
425- Fix `unstable_useBlocker` key issues in `StrictMode` ([#10573](https://github.com/remix-run/react-router/pull/10573))
426- Fix `tsc --skipLibCheck:false` issues on React 17 ([#10622](https://github.com/remix-run/react-router/pull/10622))
427- Upgrade `typescript` to 5.1 ([#10581](https://github.com/remix-run/react-router/pull/10581))
428- Updated dependencies:
429 - `@remix-run/router@1.7.0`
430
431## 6.13.0
432
433### Minor Changes
434
435- 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))
436
437 Existing behavior will no longer include `React.startTransition`:
438
439 ```jsx
440 <BrowserRouter>
441 <Routes>{/*...*/}</Routes>
442 </BrowserRouter>
443
444 <RouterProvider router={router} />
445 ```
446
447 If you wish to enable `React.startTransition`, pass the future flag to your component:
448
449 ```jsx
450 <BrowserRouter future={{ v7_startTransition: true }}>
451 <Routes>{/*...*/}</Routes>
452 </BrowserRouter>
453
454 <RouterProvider router={router} future={{ v7_startTransition: true }}/>
455 ```
456
457### Patch Changes
458
459- Work around webpack/terser `React.startTransition` minification bug in production mode ([#10588](https://github.com/remix-run/react-router/pull/10588))
460
461## 6.12.1
462
463> \[!WARNING]
464> 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.
465
466### Patch Changes
467
468- Adjust feature detection of `React.startTransition` to fix webpack + react 17 compilation error ([#10569](https://github.com/remix-run/react-router/pull/10569))
469
470## 6.12.0
471
472### Minor Changes
473
474- Wrap internal router state updates with `React.startTransition` if it exists ([#10438](https://github.com/remix-run/react-router/pull/10438))
475
476### Patch Changes
477
478- Updated dependencies:
479 - `@remix-run/router@1.6.3`
480
481## 6.11.2
482
483### Patch Changes
484
485- Fix `basename` duplication in descendant `<Routes>` inside a `<RouterProvider>` ([#10492](https://github.com/remix-run/react-router/pull/10492))
486- Updated dependencies:
487 - `@remix-run/router@1.6.2`
488
489## 6.11.1
490
491### Patch Changes
492
493- Fix usage of `Component` API within descendant `<Routes>` ([#10434](https://github.com/remix-run/react-router/pull/10434))
494- Fix bug when calling `useNavigate` from `<Routes>` inside a `<RouterProvider>` ([#10432](https://github.com/remix-run/react-router/pull/10432))
495- Fix usage of `<Navigate>` in strict mode when using a data router ([#10435](https://github.com/remix-run/react-router/pull/10435))
496- Updated dependencies:
497 - `@remix-run/router@1.6.1`
498
499## 6.11.0
500
501### Patch Changes
502
503- Log loader/action errors to the console in dev for easier stack trace evaluation ([#10286](https://github.com/remix-run/react-router/pull/10286))
504- Fix bug preventing rendering of descendant `<Routes>` when `RouterProvider` errors existed ([#10374](https://github.com/remix-run/react-router/pull/10374))
505- Fix inadvertent re-renders when using `Component` instead of `element` on a route definition ([#10287](https://github.com/remix-run/react-router/pull/10287))
506- 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))
507- 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))
508- Allow `useRevalidator()` to resolve a loader-driven error boundary scenario ([#10369](https://github.com/remix-run/react-router/pull/10369))
509- Avoid unnecessary unsubscribe/resubscribes on router state changes ([#10409](https://github.com/remix-run/react-router/pull/10409))
510- 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))
511- Updated dependencies:
512 - `@remix-run/router@1.6.0`
513
514## 6.10.0
515
516### Minor Changes
517
518- 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))
519
520 - When `future.v7_normalizeFormMethod === false` (default v6 behavior),
521 - `useNavigation().formMethod` is lowercase
522 - `useFetcher().formMethod` is lowercase
523 - When `future.v7_normalizeFormMethod === true`:
524 - `useNavigation().formMethod` is uppercase
525 - `useFetcher().formMethod` is uppercase
526
527### Patch Changes
528
529- Fix route ID generation when using Fragments in `createRoutesFromElements` ([#10193](https://github.com/remix-run/react-router/pull/10193))
530- Updated dependencies:
531 - `@remix-run/router@1.5.0`
532
533## 6.9.0
534
535### Minor Changes
536
537- 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))
538
539 **Example JSON Syntax**
540
541 ```jsx
542 // Both of these work the same:
543 const elementRoutes = [{
544 path: '/',
545 element: <Home />,
546 errorElement: <HomeError />,
547 }]
548
549 const componentRoutes = [{
550 path: '/',
551 Component: Home,
552 ErrorBoundary: HomeError,
553 }]
554
555 function Home() { ... }
556 function HomeError() { ... }
557 ```
558
559 **Example JSX Syntax**
560
561 ```jsx
562 // Both of these work the same:
563 const elementRoutes = createRoutesFromElements(
564 <Route path='/' element={<Home />} errorElement={<HomeError /> } />
565 );
566
567 const componentRoutes = createRoutesFromElements(
568 <Route path='/' Component={Home} ErrorBoundary={HomeError} />
569 );
570
571 function Home() { ... }
572 function HomeError() { ... }
573 ```
574
575- **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045))
576
577 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`).
578
579 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.
580
581 Your `lazy` functions will typically return the result of a dynamic import.
582
583 ```jsx
584 // In this example, we assume most folks land on the homepage so we include that
585 // in our critical-path bundle, but then we lazily load modules for /a and /b so
586 // they don't load until the user navigates to those routes
587 let routes = createRoutesFromElements(
588 <Route path="/" element={<Layout />}>
589 <Route index element={<Home />} />
590 <Route path="a" lazy={() => import("./a")} />
591 <Route path="b" lazy={() => import("./b")} />
592 </Route>
593 );
594 ```
595
596 Then in your lazy route modules, export the properties you want defined for the route:
597
598 ```jsx
599 export async function loader({ request }) {
600 let data = await fetchData(request);
601 return json(data);
602 }
603
604 // Export a `Component` directly instead of needing to create a React Element from it
605 export function Component() {
606 let data = useLoaderData();
607
608 return (
609 <>
610 <h1>You made it!</h1>
611 <p>{data}</p>
612 </>
613 );
614 }
615
616 // Export an `ErrorBoundary` directly instead of needing to create a React Element from it
617 export function ErrorBoundary() {
618 let error = useRouteError();
619 return isRouteErrorResponse(error) ? (
620 <h1>
621 {error.status} {error.statusText}
622 </h1>
623 ) : (
624 <h1>{error.message || error}</h1>
625 );
626 }
627 ```
628
629 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.
630
631 🙌 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).
632
633- Updated dependencies:
634 - `@remix-run/router@1.4.0`
635
636### Patch Changes
637
638- Fix `generatePath` incorrectly applying parameters in some cases ([#10078](https://github.com/remix-run/react-router/pull/10078))
639- Improve memoization for context providers to avoid unnecessary re-renders ([#9983](https://github.com/remix-run/react-router/pull/9983))
640
641## 6.8.2
642
643### Patch Changes
644
645- Updated dependencies:
646 - `@remix-run/router@1.3.3`
647
648## 6.8.1
649
650### Patch Changes
651
652- Remove inaccurate console warning for POP navigations and update active blocker logic ([#10030](https://github.com/remix-run/react-router/pull/10030))
653- Updated dependencies:
654 - `@remix-run/router@1.3.2`
655
656## 6.8.0
657
658### Patch Changes
659
660- Updated dependencies:
661 - `@remix-run/router@1.3.1`
662
663## 6.7.0
664
665### Minor Changes
666
667- Add `unstable_useBlocker` hook for blocking navigations within the app's location origin ([#9709](https://github.com/remix-run/react-router/pull/9709))
668
669### Patch Changes
670
671- Fix `generatePath` when optional params are present ([#9764](https://github.com/remix-run/react-router/pull/9764))
672- Update `<Await>` to accept `ReactNode` as children function return result ([#9896](https://github.com/remix-run/react-router/pull/9896))
673- Updated dependencies:
674 - `@remix-run/router@1.3.0`
675
676## 6.6.2
677
678### Patch Changes
679
680- Ensure `useId` consistency during SSR ([#9805](https://github.com/remix-run/react-router/pull/9805))
681
682## 6.6.1
683
684### Patch Changes
685
686- Updated dependencies:
687 - `@remix-run/router@1.2.1`
688
689## 6.6.0
690
691### Patch Changes
692
693- Prevent `useLoaderData` usage in `errorElement` ([#9735](https://github.com/remix-run/react-router/pull/9735))
694- Updated dependencies:
695 - `@remix-run/router@1.2.0`
696
697## 6.5.0
698
699This 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.
700
701**Optional Params Examples**
702
703- `<Route path=":lang?/about>` will match:
704 - `/:lang/about`
705 - `/about`
706- `<Route path="/multistep/:widget1?/widget2?/widget3?">` will match:
707 - `/multistep`
708 - `/multistep/:widget1`
709 - `/multistep/:widget1/:widget2`
710 - `/multistep/:widget1/:widget2/:widget3`
711
712**Optional Static Segment Example**
713
714- `<Route path="/home?">` will match:
715 - `/`
716 - `/home`
717- `<Route path="/fr?/about">` will match:
718 - `/about`
719 - `/fr/about`
720
721### Minor Changes
722
723- Allows optional routes and optional static segments ([#9650](https://github.com/remix-run/react-router/pull/9650))
724
725### Patch Changes
726
727- 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))
728
729```jsx
730// Old behavior at URL /prefix-123
731<Route path="prefix-:id" element={<Comp /> }>
732
733function Comp() {
734 let params = useParams(); // { id: '123' }
735 let id = params.id; // "123"
736 ...
737}
738
739// New behavior at URL /prefix-123
740<Route path=":id" element={<Comp /> }>
741
742function Comp() {
743 let params = useParams(); // { id: 'prefix-123' }
744 let id = params.id.replace(/^prefix-/, ''); // "123"
745 ...
746}
747```
748
749- Updated dependencies:
750 - `@remix-run/router@1.1.0`
751
752## 6.4.5
753
754### Patch Changes
755
756- Updated dependencies:
757 - `@remix-run/router@1.0.5`
758
759## 6.4.4
760
761### Patch Changes
762
763- Updated dependencies:
764 - `@remix-run/router@1.0.4`
765
766## 6.4.3
767
768### Patch Changes
769
770- `useRoutes` should be able to return `null` when passing `locationArg` ([#9485](https://github.com/remix-run/react-router/pull/9485))
771- fix `initialEntries` type in `createMemoryRouter` ([#9498](https://github.com/remix-run/react-router/pull/9498))
772- Updated dependencies:
773 - `@remix-run/router@1.0.3`
774
775## 6.4.2
776
777### Patch Changes
778
779- Fix `IndexRouteObject` and `NonIndexRouteObject` types to make `hasErrorElement` optional ([#9394](https://github.com/remix-run/react-router/pull/9394))
780- Enhance console error messages for invalid usage of data router hooks ([#9311](https://github.com/remix-run/react-router/pull/9311))
781- 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))
782- Updated dependencies:
783 - `@remix-run/router@1.0.2`
784
785## 6.4.1
786
787### Patch Changes
788
789- Preserve state from `initialEntries` ([#9288](https://github.com/remix-run/react-router/pull/9288))
790- Updated dependencies:
791 - `@remix-run/router@1.0.1`
792
793## 6.4.0
794
795Whoa 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).
796
797**New APIs**
798
799- Create your router with `createMemoryRouter`
800- Render your router with `<RouterProvider>`
801- Load data with a Route `loader` and mutate with a Route `action`
802- Handle errors with Route `errorElement`
803- Defer non-critical data with `defer` and `Await`
804
805**Bug Fixes**
806
807- Path resolution is now trailing slash agnostic (#8861)
808- `useLocation` returns the scoped location inside a `<Routes location>` component (#9094)
809
810**Updated Dependencies**
811
812- `@remix-run/router@1.0.0`