UNPKG

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