react-router 0.0.0-experimental-e16afd9b7 → 0.0.0-experimental-52e9b8eb3

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +10 -1
  3. package/dist/index.d.ts +16 -33
  4. package/dist/index.js +1114 -9501
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/components.d.ts +19 -189
  7. package/dist/lib/context.d.ts +4 -4
  8. package/dist/lib/hooks.d.ts +17 -46
  9. package/dist/main.js +1 -1
  10. package/dist/react-router.development.js +1152 -10370
  11. package/dist/react-router.development.js.map +1 -1
  12. package/dist/react-router.production.min.js +2 -2
  13. package/dist/react-router.production.min.js.map +1 -1
  14. package/dist/umd/react-router.development.js +1259 -10541
  15. package/dist/umd/react-router.development.js.map +1 -1
  16. package/dist/umd/react-router.production.min.js +2 -2
  17. package/dist/umd/react-router.production.min.js.map +1 -1
  18. package/package.json +4 -19
  19. package/dist/lib/dom/dom.d.ts +0 -104
  20. package/dist/lib/dom/global.d.ts +0 -38
  21. package/dist/lib/dom/lib.d.ts +0 -572
  22. package/dist/lib/dom/server.d.ts +0 -32
  23. package/dist/lib/dom/ssr/browser.d.ts +0 -3
  24. package/dist/lib/dom/ssr/components.d.ts +0 -94
  25. package/dist/lib/dom/ssr/create-remix-stub.d.ts +0 -56
  26. package/dist/lib/dom/ssr/data.d.ts +0 -7
  27. package/dist/lib/dom/ssr/errorBoundaries.d.ts +0 -33
  28. package/dist/lib/dom/ssr/errors.d.ts +0 -2
  29. package/dist/lib/dom/ssr/fallback.d.ts +0 -2
  30. package/dist/lib/dom/ssr/invariant.d.ts +0 -2
  31. package/dist/lib/dom/ssr/links.d.ts +0 -126
  32. package/dist/lib/dom/ssr/markup.d.ts +0 -5
  33. package/dist/lib/dom/ssr/routeModules.d.ts +0 -141
  34. package/dist/lib/dom/ssr/routes.d.ts +0 -32
  35. package/dist/lib/dom/ssr/server.d.ts +0 -13
  36. package/dist/lib/dom/ssr/single-fetch.d.ts +0 -37
  37. package/dist/lib/router/history.d.ts +0 -249
  38. package/dist/lib/router/index.d.ts +0 -9
  39. package/dist/lib/router/router.d.ts +0 -521
  40. package/dist/lib/router/utils.d.ts +0 -520
  41. package/dist/rsc.js +0 -1641
@@ -1,28 +1,11 @@
1
- import type { FutureConfig as RouterFutureConfig, HydrationState, InitialEntry, LazyRouteFunction, Location, RelativeRoutingType, Router as RemixRouter, To, TrackedPromise, unstable_DataStrategyFunction } from "./router";
2
- import { Action as NavigationType } from "./router";
1
+ import type { InitialEntry, LazyRouteFunction, Location, RelativeRoutingType, Router as RemixRouter, To, TrackedPromise } from "@remix-run/router";
2
+ import { Action as NavigationType } from "@remix-run/router";
3
3
  import * as React from "react";
4
4
  import type { IndexRouteObject, Navigator, NonIndexRouteObject, RouteMatch, RouteObject } from "./context";
5
5
  export interface FutureConfig {
6
6
  v7_relativeSplatPath: boolean;
7
7
  v7_startTransition: boolean;
8
8
  }
9
- /**
10
- * @private
11
- */
12
- export declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
13
- hasErrorBoundary: boolean;
14
- };
15
- /**
16
- * @category Routers
17
- */
18
- export declare function createMemoryRouter(routes: RouteObject[], opts?: {
19
- basename?: string;
20
- future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>;
21
- hydrationData?: HydrationState;
22
- initialEntries?: InitialEntry[];
23
- initialIndex?: number;
24
- unstable_dataStrategy?: unstable_DataStrategyFunction;
25
- }): RemixRouter;
26
9
  export interface RouterProviderProps {
27
10
  fallbackElement?: React.ReactNode;
28
11
  router: RemixRouter;
@@ -30,8 +13,6 @@ export interface RouterProviderProps {
30
13
  }
31
14
  /**
32
15
  * Given a Remix Router instance, render the appropriate UI
33
- *
34
- * @category Components
35
16
  */
36
17
  export declare function RouterProvider({ fallbackElement, router, future, }: RouterProviderProps): React.ReactElement;
37
18
  export interface MemoryRouterProps {
@@ -44,7 +25,7 @@ export interface MemoryRouterProps {
44
25
  /**
45
26
  * A `<Router>` that stores all entries in memory.
46
27
  *
47
- * @category Components
28
+ * @see https://reactrouter.com/router-components/memory-router
48
29
  */
49
30
  export declare function MemoryRouter({ basename, children, initialEntries, initialIndex, future, }: MemoryRouterProps): React.ReactElement;
50
31
  export interface NavigateProps {
@@ -54,44 +35,22 @@ export interface NavigateProps {
54
35
  relative?: RelativeRoutingType;
55
36
  }
56
37
  /**
57
- * A component-based version of {@link useNavigate} to use in a [`React.Component
58
- * Class`](https://reactjs.org/docs/react-component.html) where hooks are not
59
- * able to be used.
38
+ * Changes the current location.
60
39
  *
61
- * It's recommended to avoid using this component in favor of {@link useNavigate}
40
+ * Note: This API is mostly useful in React.Component subclasses that are not
41
+ * able to use hooks. In functional components, we recommend you use the
42
+ * `useNavigate` hook instead.
62
43
  *
63
- * @category Components
44
+ * @see https://reactrouter.com/components/navigate
64
45
  */
65
46
  export declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
66
47
  export interface OutletProps {
67
- /**
68
- Provides a context value to the element tree below the outlet. Use when the parent route needs to provide values to child routes.
69
-
70
- ```tsx
71
- <Outlet context={myContextValue} />
72
- ```
73
-
74
- Access the context with {@link useOutletContext}.
75
- */
76
48
  context?: unknown;
77
49
  }
78
50
  /**
79
- Renders the matching child route of a parent route or nothing if no child route matches.
80
-
81
- ```tsx
82
- import { Outlet } from "react-router"
83
-
84
- export default function SomeParent() {
85
- return (
86
- <div>
87
- <h1>Parent Content</h1>
88
- <Outlet />
89
- </div>
90
- );
91
- }
92
- ```
93
-
94
- @category Components
51
+ * Renders the child route's element, if there is one.
52
+ *
53
+ * @see https://reactrouter.com/components/outlet
95
54
  */
96
55
  export declare function Outlet(props: OutletProps): React.ReactElement | null;
97
56
  export interface PathRouteProps {
@@ -138,7 +97,7 @@ export type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
138
97
  /**
139
98
  * Declares an element that should be rendered at a certain URL path.
140
99
  *
141
- * @category Components
100
+ * @see https://reactrouter.com/components/route
142
101
  */
143
102
  export declare function Route(_props: RouteProps): React.ReactElement | null;
144
103
  export interface RouterProps {
@@ -157,7 +116,7 @@ export interface RouterProps {
157
116
  * router that is more specific to your environment such as a `<BrowserRouter>`
158
117
  * in web browsers or a `<StaticRouter>` for server rendering.
159
118
  *
160
- * @category Components
119
+ * @see https://reactrouter.com/router-components/router
161
120
  */
162
121
  export declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, future, }: RouterProps): React.ReactElement | null;
163
122
  export interface RoutesProps {
@@ -168,157 +127,28 @@ export interface RoutesProps {
168
127
  * A container for a nested tree of `<Route>` elements that renders the branch
169
128
  * that best matches the current location.
170
129
  *
171
- * @category Components
130
+ * @see https://reactrouter.com/components/routes
172
131
  */
173
132
  export declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
174
133
  export interface AwaitResolveRenderFunction {
175
134
  (data: Awaited<any>): React.ReactNode;
176
135
  }
177
136
  export interface AwaitProps {
178
- /**
179
- When using a function, the resolved value is provided as the parameter.
180
-
181
- ```tsx [2]
182
- <Await resolve={reviewsPromise}>
183
- {(resolvedReviews) => <Reviews items={resolvedReviews} />}
184
- </Await>
185
- ```
186
-
187
- When using React elements, {@link useAsyncValue} will provide the
188
- resolved value:
189
-
190
- ```tsx [2]
191
- <Await resolve={reviewsPromise}>
192
- <Reviews />
193
- </Await>
194
-
195
- function Reviews() {
196
- const resolvedReviews = useAsyncValue()
197
- return <div>...</div>
198
- }
199
- ```
200
- */
201
137
  children: React.ReactNode | AwaitResolveRenderFunction;
202
- /**
203
- The error element renders instead of the children when the promise rejects.
204
-
205
- ```tsx
206
- <Await
207
- errorElement={<div>Oops</div>}
208
- resolve={reviewsPromise}
209
- >
210
- <Reviews />
211
- </Await>
212
- ```
213
-
214
- To provide a more contextual error, you can use the {@link useAsyncError} in a
215
- child component
216
-
217
- ```tsx
218
- <Await
219
- errorElement={<ReviewsError />}
220
- resolve={reviewsPromise}
221
- >
222
- <Reviews />
223
- </Await>
224
-
225
- function ReviewsError() {
226
- const error = useAsyncError()
227
- return <div>Error loading reviews: {error.message}</div>
228
- }
229
- ```
230
-
231
- If you do not provide an errorElement, the rejected value will bubble up to
232
- the nearest route-level {@link NonIndexRouteObject#ErrorBoundary | ErrorBoundary} and be accessible
233
- via {@link useRouteError} hook.
234
- */
235
138
  errorElement?: React.ReactNode;
236
- /**
237
- Takes a promise returned from a {@link LoaderFunction | loader} value to be resolved and rendered.
238
-
239
- ```jsx
240
- import { useLoaderData, Await } from "react-router"
241
-
242
- export async function loader() {
243
- let reviews = getReviews() // not awaited
244
- let book = await getBook()
245
- return {
246
- book,
247
- reviews, // this is a promise
248
- }
249
- }
250
-
251
- export default function Book() {
252
- const {
253
- book,
254
- reviews, // this is the same promise
255
- } = useLoaderData()
256
-
257
- return (
258
- <div>
259
- <h1>{book.title}</h1>
260
- <p>{book.description}</p>
261
- <React.Suspense fallback={<ReviewsSkeleton />}>
262
- <Await
263
- // and is the promise we pass to Await
264
- resolve={reviews}
265
- >
266
- <Reviews />
267
- </Await>
268
- </React.Suspense>
269
- </div>
270
- );
271
- }
272
- ```
273
- */
274
139
  resolve: TrackedPromise | any;
275
140
  }
276
141
  /**
277
- Used to render promise values with automatic error handling.
278
-
279
- ```tsx
280
- import { Await, useLoaderData } from "react-router";
281
-
282
- export function loader() {
283
- // not awaited
284
- const reviews = getReviews()
285
- // awaited (blocks the transition)
286
- const book = await fetch("/api/book").then((res) => res.json())
287
- return { book, reviews }
288
- }
289
-
290
- function Book() {
291
- const { book, reviews } = useLoaderData();
292
- return (
293
- <div>
294
- <h1>{book.title}</h1>
295
- <p>{book.description}</p>
296
- <React.Suspense fallback={<ReviewsSkeleton />}>
297
- <Await
298
- resolve={reviews}
299
- errorElement={
300
- <div>Could not load reviews 😬</div>
301
- }
302
- children={(resolvedReviews) => (
303
- <Reviews items={resolvedReviews} />
304
- )}
305
- />
306
- </React.Suspense>
307
- </div>
308
- );
309
- }
310
- ```
311
-
312
- **Note:** `<Await>` expects to be rendered inside of a `<React.Suspense>`
313
-
314
- @category Components
315
-
316
- */
142
+ * Component to use for rendering lazily loaded data from returning defer()
143
+ * in a loader function
144
+ */
317
145
  export declare function Await({ children, errorElement, resolve }: AwaitProps): React.JSX.Element;
318
146
  /**
319
147
  * Creates a route config from a React "children" object, which is usually
320
148
  * either a `<Route>` element or an array of them. Used internally by
321
149
  * `<Routes>` to create a route config from its children.
150
+ *
151
+ * @see https://reactrouter.com/utils/create-routes-from-children
322
152
  */
323
153
  export declare function createRoutesFromChildren(children: React.ReactNode, parentPath?: number[]): RouteObject[];
324
154
  /**
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import type { AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, History, LazyRouteFunction, Location, Action as NavigationType, RelativeRoutingType, Router, StaticHandlerContext, To, TrackedPromise } from "./router";
2
+ import type { AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, History, LazyRouteFunction, Location, Action as NavigationType, RelativeRoutingType, Router, StaticHandlerContext, To, TrackedPromise } from "@remix-run/router";
3
3
  export interface IndexRouteObject {
4
4
  caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
5
5
  path?: AgnosticIndexRouteObject["path"];
@@ -29,7 +29,7 @@ export interface NonIndexRouteObject {
29
29
  shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
30
30
  handle?: AgnosticNonIndexRouteObject["handle"];
31
31
  index?: false;
32
- children?: RouteObject[];
32
+ children?: RouteObject[] | (() => Promise<RouteObject[]>);
33
33
  element?: React.ReactNode | null;
34
34
  hydrateFallbackElement?: React.ReactNode | null;
35
35
  errorElement?: React.ReactNode | null;
@@ -40,7 +40,7 @@ export interface NonIndexRouteObject {
40
40
  }
41
41
  export type RouteObject = IndexRouteObject | NonIndexRouteObject;
42
42
  export type DataRouteObject = RouteObject & {
43
- children?: DataRouteObject[];
43
+ children?: DataRouteObject[] | (() => Promise<DataRouteObject[]>);
44
44
  id: string;
45
45
  };
46
46
  export interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
@@ -52,7 +52,7 @@ export interface DataRouterContextObject extends Omit<NavigationContextObject, "
52
52
  staticContext?: StaticHandlerContext;
53
53
  }
54
54
  export declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
55
- export declare const DataRouterStateContext: React.Context<import("./router").RouterState | null>;
55
+ export declare const DataRouterStateContext: React.Context<import("@remix-run/router").RouterState | null>;
56
56
  export declare const AwaitContext: React.Context<TrackedPromise | null>;
57
57
  export interface NavigateOptions {
58
58
  replace?: boolean;
@@ -1,12 +1,12 @@
1
1
  import * as React from "react";
2
- import type { Blocker, BlockerFunction, Location, ParamParseKey, Params, Path, PathMatch, PathPattern, RelativeRoutingType, Router as RemixRouter, RevalidationState, To, UIMatch } from "./router";
3
- import { Action as NavigationType } from "./router";
2
+ import type { Blocker, BlockerFunction, Location, ParamParseKey, Params, Path, PathMatch, PathPattern, RelativeRoutingType, Router as RemixRouter, RevalidationState, To, UIMatch } from "@remix-run/router";
3
+ import { Action as NavigationType } from "@remix-run/router";
4
4
  import type { NavigateOptions, RouteContextObject, RouteMatch, RouteObject } from "./context";
5
5
  /**
6
6
  * Returns the full href for the given "to" value. This is useful for building
7
7
  * custom links that are also accessible and preserve right-click behavior.
8
8
  *
9
- * @category Hooks
9
+ * @see https://reactrouter.com/hooks/use-href
10
10
  */
11
11
  export declare function useHref(to: To, { relative }?: {
12
12
  relative?: RelativeRoutingType;
@@ -14,7 +14,7 @@ export declare function useHref(to: To, { relative }?: {
14
14
  /**
15
15
  * Returns true if this component is a descendant of a `<Router>`.
16
16
  *
17
- * @category Hooks
17
+ * @see https://reactrouter.com/hooks/use-in-router-context
18
18
  */
19
19
  export declare function useInRouterContext(): boolean;
20
20
  /**
@@ -25,14 +25,14 @@ export declare function useInRouterContext(): boolean;
25
25
  * "routing" in your app, and we'd like to know what your use case is. We may
26
26
  * be able to provide something higher-level to better suit your needs.
27
27
  *
28
- * @category Hooks
28
+ * @see https://reactrouter.com/hooks/use-location
29
29
  */
30
30
  export declare function useLocation(): Location;
31
31
  /**
32
32
  * Returns the current navigation action which describes how the router came to
33
33
  * the current location, either by a pop, push, or replace on the history stack.
34
34
  *
35
- * @category Hooks
35
+ * @see https://reactrouter.com/hooks/use-navigation-type
36
36
  */
37
37
  export declare function useNavigationType(): NavigationType;
38
38
  /**
@@ -40,44 +40,41 @@ export declare function useNavigationType(): NavigationType;
40
40
  * This is useful for components that need to know "active" state, e.g.
41
41
  * `<NavLink>`.
42
42
  *
43
- * @category Hooks
43
+ * @see https://reactrouter.com/hooks/use-match
44
44
  */
45
45
  export declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null;
46
46
  /**
47
47
  * The interface for the navigate() function returned from useNavigate().
48
- *
49
- * @category Types
50
48
  */
51
49
  export interface NavigateFunction {
52
- (to: To, options?: NavigateOptions): void | Promise<void>;
53
- (delta: number): void | Promise<void>;
50
+ (to: To, options?: NavigateOptions): void;
51
+ (delta: number): void;
54
52
  }
55
53
  /**
56
54
  * Returns an imperative method for changing the location. Used by `<Link>`s, but
57
55
  * may also be used by other elements to change the location.
58
56
  *
59
- * @category Hooks
57
+ * @see https://reactrouter.com/hooks/use-navigate
60
58
  */
61
59
  export declare function useNavigate(): NavigateFunction;
62
60
  /**
63
61
  * Returns the context (if provided) for the child route at this level of the route
64
62
  * hierarchy.
65
- *
66
- * @category Hooks
63
+ * @see https://reactrouter.com/hooks/use-outlet-context
67
64
  */
68
65
  export declare function useOutletContext<Context = unknown>(): Context;
69
66
  /**
70
67
  * Returns the element for the child route at this level of the route
71
68
  * hierarchy. Used internally by `<Outlet>` to render child routes.
72
69
  *
73
- * @category Hooks
70
+ * @see https://reactrouter.com/hooks/use-outlet
74
71
  */
75
72
  export declare function useOutlet(context?: unknown): React.ReactElement | null;
76
73
  /**
77
74
  * Returns an object of key/value pairs of the dynamic params from the current
78
75
  * URL that were matched by the route path.
79
76
  *
80
- * @category Hooks
77
+ * @see https://reactrouter.com/hooks/use-params
81
78
  */
82
79
  export declare function useParams<ParamsOrKey extends string | Record<string, string | undefined> = string>(): Readonly<[
83
80
  ParamsOrKey
@@ -85,7 +82,7 @@ export declare function useParams<ParamsOrKey extends string | Record<string, st
85
82
  /**
86
83
  * Resolves the pathname of the given `to` value against the current location.
87
84
  *
88
- * @category Hooks
85
+ * @see https://reactrouter.com/hooks/use-resolved-path
89
86
  */
90
87
  export declare function useResolvedPath(to: To, { relative }?: {
91
88
  relative?: RelativeRoutingType;
@@ -96,15 +93,9 @@ export declare function useResolvedPath(to: To, { relative }?: {
96
93
  * elements in the tree must render an `<Outlet>` to render their child route's
97
94
  * element.
98
95
  *
99
- * @category Hooks
96
+ * @see https://reactrouter.com/hooks/use-routes
100
97
  */
101
98
  export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
102
- /**
103
- * Internal implementation with accept optional param for RouterProvider usage
104
- *
105
- * @private
106
- * @category Hooks
107
- */
108
99
  export declare function useRoutesImpl(routes: RouteObject[], locationArg?: Partial<Location> | string, dataRouterState?: RemixRouter["state"], future?: RemixRouter["future"]): React.ReactElement | null;
109
100
  type RenderErrorBoundaryProps = React.PropsWithChildren<{
110
101
  location: Location;
@@ -139,63 +130,45 @@ export declare function useRouteId(): string;
139
130
  /**
140
131
  * Returns the current navigation, defaulting to an "idle" navigation when
141
132
  * no navigation is in progress
142
- *
143
- * @category Hooks
144
133
  */
145
- export declare function useNavigation(): import("./router").Navigation;
134
+ export declare function useNavigation(): import("@remix-run/router").Navigation;
146
135
  /**
147
136
  * Returns a revalidate function for manually triggering revalidation, as well
148
137
  * as the current state of any manual revalidations
149
- *
150
- * @category Hooks
151
138
  */
152
139
  export declare function useRevalidator(): {
153
- revalidate(): Promise<void>;
140
+ revalidate: () => void;
154
141
  state: RevalidationState;
155
142
  };
156
143
  /**
157
144
  * Returns the active route matches, useful for accessing loaderData for
158
145
  * parent/child routes or the route "handle" property
159
- *
160
- * @category Hooks
161
146
  */
162
147
  export declare function useMatches(): UIMatch[];
163
148
  /**
164
149
  * Returns the loader data for the nearest ancestor Route loader
165
- *
166
- * @category Hooks
167
150
  */
168
151
  export declare function useLoaderData(): unknown;
169
152
  /**
170
153
  * Returns the loaderData for the given routeId
171
- *
172
- * @category Hooks
173
154
  */
174
155
  export declare function useRouteLoaderData(routeId: string): unknown;
175
156
  /**
176
157
  * Returns the action data for the nearest ancestor Route action
177
- *
178
- * @category Hooks
179
158
  */
180
159
  export declare function useActionData(): unknown;
181
160
  /**
182
161
  * Returns the nearest ancestor Route error, which could be a loader/action
183
162
  * error or a render error. This is intended to be called from your
184
163
  * ErrorBoundary/errorElement to display a proper error message.
185
- *
186
- * @category Hooks
187
164
  */
188
165
  export declare function useRouteError(): unknown;
189
166
  /**
190
167
  * Returns the happy-path data from the nearest ancestor `<Await />` value
191
- *
192
- * @category Hooks
193
168
  */
194
169
  export declare function useAsyncValue(): unknown;
195
170
  /**
196
171
  * Returns the error from the nearest ancestor `<Await />` value
197
- *
198
- * @category Hooks
199
172
  */
200
173
  export declare function useAsyncError(): unknown;
201
174
  /**
@@ -203,8 +176,6 @@ export declare function useAsyncError(): unknown;
203
176
  * user a confirmation dialog to confirm the navigation. Mostly used to avoid
204
177
  * using half-filled form data. This does not handle hard-reloads or
205
178
  * cross-origin navigations.
206
- *
207
- * @category Hooks
208
179
  */
209
180
  export declare function useBlocker(shouldBlock: boolean | BlockerFunction): Blocker;
210
181
  export {};
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-e16afd9b7
2
+ * React Router v0.0.0-experimental-52e9b8eb3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *