UNPKG

15.9 kBMarkdownView Raw
1# `react-router`
2
3## 6.14.0
4
5### Patch Changes
6
7- Strip `basename` from locations provided to `unstable_useBlocker` functions to match `useLocation` ([#10573](https://github.com/remix-run/react-router/pull/10573))
8- Fix `generatePath` when passed a numeric `0` value parameter ([#10612](https://github.com/remix-run/react-router/pull/10612))
9- Fix `unstable_useBlocker` key issues in `StrictMode` ([#10573](https://github.com/remix-run/react-router/pull/10573))
10- Fix `tsc --skipLibCheck:false` issues on React 17 ([#10622](https://github.com/remix-run/react-router/pull/10622))
11- Upgrade `typescript` to 5.1 ([#10581](https://github.com/remix-run/react-router/pull/10581))
12- Updated dependencies:
13 - `@remix-run/router@1.7.0`
14
15## 6.13.0
16
17### Minor Changes
18
19- 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))
20
21 Existing behavior will no longer include `React.startTransition`:
22
23 ```jsx
24 <BrowserRouter>
25 <Routes>{/*...*/}</Routes>
26 </BrowserRouter>
27
28 <RouterProvider router={router} />
29 ```
30
31 If you wish to enable `React.startTransition`, pass the future flag to your component:
32
33 ```jsx
34 <BrowserRouter future={{ v7_startTransition: true }}>
35 <Routes>{/*...*/}</Routes>
36 </BrowserRouter>
37
38 <RouterProvider router={router} future={{ v7_startTransition: true }}/>
39 ```
40
41### Patch Changes
42
43- Work around webpack/terser `React.startTransition` minification bug in production mode ([#10588](https://github.com/remix-run/react-router/pull/10588))
44
45## 6.12.1
46
47> **Warning**
48> 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.
49
50### Patch Changes
51
52- Adjust feature detection of `React.startTransition` to fix webpack + react 17 compilation error ([#10569](https://github.com/remix-run/react-router/pull/10569))
53
54## 6.12.0
55
56### Minor Changes
57
58- Wrap internal router state updates with `React.startTransition` if it exists ([#10438](https://github.com/remix-run/react-router/pull/10438))
59
60### Patch Changes
61
62- Updated dependencies:
63 - `@remix-run/router@1.6.3`
64
65## 6.11.2
66
67### Patch Changes
68
69- Fix `basename` duplication in descendant `<Routes>` inside a `<RouterProvider>` ([#10492](https://github.com/remix-run/react-router/pull/10492))
70- Updated dependencies:
71 - `@remix-run/router@1.6.2`
72
73## 6.11.1
74
75### Patch Changes
76
77- Fix usage of `Component` API within descendant `<Routes>` ([#10434](https://github.com/remix-run/react-router/pull/10434))
78- Fix bug when calling `useNavigate` from `<Routes>` inside a `<RouterProvider>` ([#10432](https://github.com/remix-run/react-router/pull/10432))
79- Fix usage of `<Navigate>` in strict mode when using a data router ([#10435](https://github.com/remix-run/react-router/pull/10435))
80- Updated dependencies:
81 - `@remix-run/router@1.6.1`
82
83## 6.11.0
84
85### Patch Changes
86
87- Log loader/action errors to the console in dev for easier stack trace evaluation ([#10286](https://github.com/remix-run/react-router/pull/10286))
88- Fix bug preventing rendering of descendant `<Routes>` when `RouterProvider` errors existed ([#10374](https://github.com/remix-run/react-router/pull/10374))
89- Fix inadvertent re-renders when using `Component` instead of `element` on a route definition ([#10287](https://github.com/remix-run/react-router/pull/10287))
90- 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))
91- 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))
92- Allow `useRevalidator()` to resolve a loader-driven error boundary scenario ([#10369](https://github.com/remix-run/react-router/pull/10369))
93- Avoid unnecessary unsubscribe/resubscribes on router state changes ([#10409](https://github.com/remix-run/react-router/pull/10409))
94- 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))
95- Updated dependencies:
96 - `@remix-run/router@1.6.0`
97
98## 6.10.0
99
100### Minor Changes
101
102- 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))
103
104 - When `future.v7_normalizeFormMethod === false` (default v6 behavior),
105 - `useNavigation().formMethod` is lowercase
106 - `useFetcher().formMethod` is lowercase
107 - When `future.v7_normalizeFormMethod === true`:
108 - `useNavigation().formMethod` is uppercase
109 - `useFetcher().formMethod` is uppercase
110
111### Patch Changes
112
113- Fix route ID generation when using Fragments in `createRoutesFromElements` ([#10193](https://github.com/remix-run/react-router/pull/10193))
114- Updated dependencies:
115 - `@remix-run/router@1.5.0`
116
117## 6.9.0
118
119### Minor Changes
120
121- 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))
122
123 **Example JSON Syntax**
124
125 ```jsx
126 // Both of these work the same:
127 const elementRoutes = [{
128 path: '/',
129 element: <Home />,
130 errorElement: <HomeError />,
131 }]
132
133 const componentRoutes = [{
134 path: '/',
135 Component: Home,
136 ErrorBoundary: HomeError,
137 }]
138
139 function Home() { ... }
140 function HomeError() { ... }
141 ```
142
143 **Example JSX Syntax**
144
145 ```jsx
146 // Both of these work the same:
147 const elementRoutes = createRoutesFromElements(
148 <Route path='/' element={<Home />} errorElement={<HomeError /> } />
149 );
150
151 const componentRoutes = createRoutesFromElements(
152 <Route path='/' Component={Home} ErrorBoundary={HomeError} />
153 );
154
155 function Home() { ... }
156 function HomeError() { ... }
157 ```
158
159- **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045))
160
161 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`).
162
163 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.
164
165 Your `lazy` functions will typically return the result of a dynamic import.
166
167 ```jsx
168 // In this example, we assume most folks land on the homepage so we include that
169 // in our critical-path bundle, but then we lazily load modules for /a and /b so
170 // they don't load until the user navigates to those routes
171 let routes = createRoutesFromElements(
172 <Route path="/" element={<Layout />}>
173 <Route index element={<Home />} />
174 <Route path="a" lazy={() => import("./a")} />
175 <Route path="b" lazy={() => import("./b")} />
176 </Route>
177 );
178 ```
179
180 Then in your lazy route modules, export the properties you want defined for the route:
181
182 ```jsx
183 export async function loader({ request }) {
184 let data = await fetchData(request);
185 return json(data);
186 }
187
188 // Export a `Component` directly instead of needing to create a React Element from it
189 export function Component() {
190 let data = useLoaderData();
191
192 return (
193 <>
194 <h1>You made it!</h1>
195 <p>{data}</p>
196 </>
197 );
198 }
199
200 // Export an `ErrorBoundary` directly instead of needing to create a React Element from it
201 export function ErrorBoundary() {
202 let error = useRouteError();
203 return isRouteErrorResponse(error) ? (
204 <h1>
205 {error.status} {error.statusText}
206 </h1>
207 ) : (
208 <h1>{error.message || error}</h1>
209 );
210 }
211 ```
212
213 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.
214
215 🙌 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).
216
217- Updated dependencies:
218 - `@remix-run/router@1.4.0`
219
220### Patch Changes
221
222- Fix `generatePath` incorrectly applying parameters in some cases ([#10078](https://github.com/remix-run/react-router/pull/10078))
223- Improve memoization for context providers to avoid unnecessary re-renders ([#9983](https://github.com/remix-run/react-router/pull/9983))
224
225## 6.8.2
226
227### Patch Changes
228
229- Updated dependencies:
230 - `@remix-run/router@1.3.3`
231
232## 6.8.1
233
234### Patch Changes
235
236- Remove inaccurate console warning for POP navigations and update active blocker logic ([#10030](https://github.com/remix-run/react-router/pull/10030))
237- Updated dependencies:
238 - `@remix-run/router@1.3.2`
239
240## 6.8.0
241
242### Patch Changes
243
244- Updated dependencies:
245 - `@remix-run/router@1.3.1`
246
247## 6.7.0
248
249### Minor Changes
250
251- Add `unstable_useBlocker` hook for blocking navigations within the app's location origin ([#9709](https://github.com/remix-run/react-router/pull/9709))
252
253### Patch Changes
254
255- Fix `generatePath` when optional params are present ([#9764](https://github.com/remix-run/react-router/pull/9764))
256- Update `<Await>` to accept `ReactNode` as children function return result ([#9896](https://github.com/remix-run/react-router/pull/9896))
257- Updated dependencies:
258 - `@remix-run/router@1.3.0`
259
260## 6.6.2
261
262### Patch Changes
263
264- Ensure `useId` consistency during SSR ([#9805](https://github.com/remix-run/react-router/pull/9805))
265
266## 6.6.1
267
268### Patch Changes
269
270- Updated dependencies:
271 - `@remix-run/router@1.2.1`
272
273## 6.6.0
274
275### Patch Changes
276
277- Prevent `useLoaderData` usage in `errorElement` ([#9735](https://github.com/remix-run/react-router/pull/9735))
278- Updated dependencies:
279 - `@remix-run/router@1.2.0`
280
281## 6.5.0
282
283This 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.
284
285**Optional Params Examples**
286
287- `<Route path=":lang?/about>` will match:
288 - `/:lang/about`
289 - `/about`
290- `<Route path="/multistep/:widget1?/widget2?/widget3?">` will match:
291 - `/multistep`
292 - `/multistep/:widget1`
293 - `/multistep/:widget1/:widget2`
294 - `/multistep/:widget1/:widget2/:widget3`
295
296**Optional Static Segment Example**
297
298- `<Route path="/home?">` will match:
299 - `/`
300 - `/home`
301- `<Route path="/fr?/about">` will match:
302 - `/about`
303 - `/fr/about`
304
305### Minor Changes
306
307- Allows optional routes and optional static segments ([#9650](https://github.com/remix-run/react-router/pull/9650))
308
309### Patch Changes
310
311- 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))
312
313```jsx
314// Old behavior at URL /prefix-123
315<Route path="prefix-:id" element={<Comp /> }>
316
317function Comp() {
318 let params = useParams(); // { id: '123' }
319 let id = params.id; // "123"
320 ...
321}
322
323// New behavior at URL /prefix-123
324<Route path=":id" element={<Comp /> }>
325
326function Comp() {
327 let params = useParams(); // { id: 'prefix-123' }
328 let id = params.id.replace(/^prefix-/, ''); // "123"
329 ...
330}
331```
332
333- Updated dependencies:
334 - `@remix-run/router@1.1.0`
335
336## 6.4.5
337
338### Patch Changes
339
340- Updated dependencies:
341 - `@remix-run/router@1.0.5`
342
343## 6.4.4
344
345### Patch Changes
346
347- Updated dependencies:
348 - `@remix-run/router@1.0.4`
349
350## 6.4.3
351
352### Patch Changes
353
354- `useRoutes` should be able to return `null` when passing `locationArg` ([#9485](https://github.com/remix-run/react-router/pull/9485))
355- fix `initialEntries` type in `createMemoryRouter` ([#9498](https://github.com/remix-run/react-router/pull/9498))
356- Updated dependencies:
357 - `@remix-run/router@1.0.3`
358
359## 6.4.2
360
361### Patch Changes
362
363- Fix `IndexRouteObject` and `NonIndexRouteObject` types to make `hasErrorElement` optional ([#9394](https://github.com/remix-run/react-router/pull/9394))
364- Enhance console error messages for invalid usage of data router hooks ([#9311](https://github.com/remix-run/react-router/pull/9311))
365- 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))
366- Updated dependencies:
367 - `@remix-run/router@1.0.2`
368
369## 6.4.1
370
371### Patch Changes
372
373- Preserve state from `initialEntries` ([#9288](https://github.com/remix-run/react-router/pull/9288))
374- Updated dependencies:
375 - `@remix-run/router@1.0.1`
376
377## 6.4.0
378
379Whoa 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][rr-docs], especially the [feature overview][rr-feature-overview] and the [tutorial][rr-tutorial].
380
381**New APIs**
382
383- Create your router with `createMemoryRouter`
384- Render your router with `<RouterProvider>`
385- Load data with a Route `loader` and mutate with a Route `action`
386- Handle errors with Route `errorElement`
387- Defer non-critical data with `defer` and `Await`
388
389**Bug Fixes**
390
391- Path resolution is now trailing slash agnostic (#8861)
392- `useLocation` returns the scoped location inside a `<Routes location>` component (#9094)
393
394**Updated Dependencies**
395
396- `@remix-run/router@1.0.0`
397
398[rr-docs]: https://reactrouter.com
399[rr-feature-overview]: https://reactrouter.com/start/overview
400[rr-tutorial]: https://reactrouter.com/start/tutorial