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