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