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