UNPKG

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