@remix-run/router 0.0.0-experimental-e7e9ce6e → 0.0.0-experimental-5f6f59a6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -4
- package/dist/history.d.ts +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/router.cjs.js +234 -121
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +6 -6
- package/dist/router.js +230 -121
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +234 -121
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +25 -6
- package/history.ts +1 -1
- package/index.ts +6 -2
- package/package.json +1 -1
- package/router.ts +243 -57
- package/utils.ts +102 -69
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,78 @@
|
|
|
1
1
|
# `@remix-run/router`
|
|
2
2
|
|
|
3
|
-
## 1.
|
|
3
|
+
## 1.4.0-pre.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045))
|
|
8
|
+
|
|
9
|
+
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`).
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
Your `lazy` functions will typically return the result of a dynamic import.
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
// In this example, we assume most folks land on the homepage so we include that
|
|
17
|
+
// in our critical-path bundle, but then we lazily load modules for /a and /b so
|
|
18
|
+
// they don't load until the user navigates to those routes
|
|
19
|
+
let routes = createRoutesFromElements(
|
|
20
|
+
<Route path="/" element={<Layout />}>
|
|
21
|
+
<Route index element={<Home />} />
|
|
22
|
+
<Route path="a" lazy={() => import("./a")} />
|
|
23
|
+
<Route path="b" lazy={() => import("./b")} />
|
|
24
|
+
</Route>
|
|
25
|
+
);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Then in your lazy route modules, export the properties you want defined for the route:
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
export async function loader({ request }) {
|
|
32
|
+
let data = await fetchData(request);
|
|
33
|
+
return json(data);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Export a `Component` directly instead of needing to create a React Element from it
|
|
37
|
+
export function Component() {
|
|
38
|
+
let data = useLoaderData();
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<h1>You made it!</h1>
|
|
43
|
+
<p>{data}</p>
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Export an `ErrorBoundary` directly instead of needing to create a React Element from it
|
|
49
|
+
export function ErrorBoundary() {
|
|
50
|
+
let error = useRouteError();
|
|
51
|
+
return isRouteErrorResponse(error) ? (
|
|
52
|
+
<h1>
|
|
53
|
+
{error.status} {error.statusText}
|
|
54
|
+
</h1>
|
|
55
|
+
) : (
|
|
56
|
+
<h1>{error.message || error}</h1>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
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.
|
|
62
|
+
|
|
63
|
+
🙌 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).
|
|
4
64
|
|
|
5
65
|
### Patch Changes
|
|
6
66
|
|
|
7
|
-
-
|
|
67
|
+
- Fix `generatePath` incorrectly applying parameters in some cases ([`bc6fefa1`](https://github.com/remix-run/react-router/commit/bc6fefa19019ce9f5250c8b5af9b8c5d3390e9d1))
|
|
8
68
|
|
|
9
|
-
## 1.3.3
|
|
69
|
+
## 1.3.3
|
|
10
70
|
|
|
11
71
|
### Patch Changes
|
|
12
72
|
|
|
13
|
-
-
|
|
73
|
+
- Correctly perform a hard redirect for same-origin absolute URLs outside of the router `basename` ([#10076](https://github.com/remix-run/react-router/pull/10076))
|
|
14
74
|
- Ensure status code and headers are maintained for `defer` loader responses in `createStaticHandler`'s `query()` method ([#10077](https://github.com/remix-run/react-router/pull/10077))
|
|
75
|
+
- Change `invariant` to an `UNSAFE_invariant` export since it's only intended for internal use ([#10066](https://github.com/remix-run/react-router/pull/10066))
|
|
15
76
|
- Add internal API for custom HMR implementations ([#9996](https://github.com/remix-run/react-router/pull/9996))
|
|
16
77
|
|
|
17
78
|
## 1.3.2
|
package/dist/history.d.ts
CHANGED
|
@@ -229,6 +229,7 @@ export declare function createHashHistory(options?: HashHistoryOptions): HashHis
|
|
|
229
229
|
*/
|
|
230
230
|
export declare function invariant(value: boolean, message?: string): asserts value;
|
|
231
231
|
export declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
|
|
232
|
+
export declare function warning(cond: any, message: string): void;
|
|
232
233
|
/**
|
|
233
234
|
* Creates a Location object with a unique key from the given Path
|
|
234
235
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, Submission, } from "./utils";
|
|
2
|
-
export { AbortedDeferredError, ErrorResponse, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename,
|
|
1
|
+
export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, LazyRouteFunction, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, Submission, } from "./utils";
|
|
2
|
+
export { AbortedDeferredError, ErrorResponse, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename, } from "./utils";
|
|
3
3
|
export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
|
|
4
4
|
export { Action, createBrowserHistory, createPath, createHashHistory, createMemoryHistory, parsePath, } from "./history";
|
|
5
5
|
export * from "./router";
|
|
6
6
|
/** @internal */
|
|
7
|
+
export type { RouteManifest as UNSAFE_RouteManifest } from "./utils";
|
|
7
8
|
export { DeferredData as UNSAFE_DeferredData, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, } from "./utils";
|
|
8
|
-
export { invariant as UNSAFE_invariant } from "./history";
|
|
9
|
+
export { invariant as UNSAFE_invariant, warning as UNSAFE_warning, } from "./history";
|