UNPKG

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