react-router 6.2.2 → 6.3.0

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/index.d.ts CHANGED
@@ -1,341 +1,14 @@
1
- import * as React from "react";
2
- import type { Hash, History, InitialEntry, Location, Path, Pathname, Search, To } from "history";
1
+ import type { Hash, Location, Path, Pathname, Search, To } from "history";
3
2
  import { Action as NavigationType, parsePath, createPath } from "history";
4
- export { parsePath, createPath, NavigationType };
5
- export type { Hash, Location, Path, Pathname, Search, To };
6
- /**
7
- * A Navigator is a "location changer"; it's how you get to different locations.
8
- *
9
- * Every history instance conforms to the Navigator interface, but the
10
- * distinction is useful primarily when it comes to the low-level <Router> API
11
- * where both the location and a navigator must be provided separately in order
12
- * to avoid "tearing" that may occur in a suspense-enabled app if the action
13
- * and/or location were to be read directly from the history instance.
14
- */
15
- export declare type Navigator = Pick<History, "go" | "push" | "replace" | "createHref">;
16
- interface NavigationContextObject {
17
- basename: string;
18
- navigator: Navigator;
19
- static: boolean;
20
- }
21
- declare const NavigationContext: React.Context<NavigationContextObject>;
22
- interface LocationContextObject {
23
- location: Location;
24
- navigationType: NavigationType;
25
- }
26
- declare const LocationContext: React.Context<LocationContextObject>;
27
- interface RouteContextObject {
28
- outlet: React.ReactElement | null;
29
- matches: RouteMatch[];
30
- }
31
- declare const RouteContext: React.Context<RouteContextObject>;
32
- export interface MemoryRouterProps {
33
- basename?: string;
34
- children?: React.ReactNode;
35
- initialEntries?: InitialEntry[];
36
- initialIndex?: number;
37
- }
38
- /**
39
- * A <Router> that stores all entries in memory.
40
- *
41
- * @see https://reactrouter.com/docs/en/v6/api#memoryrouter
42
- */
43
- export declare function MemoryRouter({ basename, children, initialEntries, initialIndex, }: MemoryRouterProps): React.ReactElement;
44
- export interface NavigateProps {
45
- to: To;
46
- replace?: boolean;
47
- state?: any;
48
- }
49
- /**
50
- * Changes the current location.
51
- *
52
- * Note: This API is mostly useful in React.Component subclasses that are not
53
- * able to use hooks. In functional components, we recommend you use the
54
- * `useNavigate` hook instead.
55
- *
56
- * @see https://reactrouter.com/docs/en/v6/api#navigate
57
- */
58
- export declare function Navigate({ to, replace, state }: NavigateProps): null;
59
- export interface OutletProps {
60
- context?: unknown;
61
- }
62
- /**
63
- * Renders the child route's element, if there is one.
64
- *
65
- * @see https://reactrouter.com/docs/en/v6/api#outlet
66
- */
67
- export declare function Outlet(props: OutletProps): React.ReactElement | null;
68
- export interface RouteProps {
69
- caseSensitive?: boolean;
70
- children?: React.ReactNode;
71
- element?: React.ReactNode | null;
72
- index?: boolean;
73
- path?: string;
74
- }
75
- export interface PathRouteProps {
76
- caseSensitive?: boolean;
77
- children?: React.ReactNode;
78
- element?: React.ReactNode | null;
79
- index?: false;
80
- path: string;
81
- }
82
- export interface LayoutRouteProps {
83
- children?: React.ReactNode;
84
- element?: React.ReactNode | null;
85
- }
86
- export interface IndexRouteProps {
87
- element?: React.ReactNode | null;
88
- index: true;
89
- }
90
- /**
91
- * Declares an element that should be rendered at a certain URL path.
92
- *
93
- * @see https://reactrouter.com/docs/en/v6/api#route
94
- */
95
- export declare function Route(_props: PathRouteProps | LayoutRouteProps | IndexRouteProps): React.ReactElement | null;
96
- export interface RouterProps {
97
- basename?: string;
98
- children?: React.ReactNode;
99
- location: Partial<Location> | string;
100
- navigationType?: NavigationType;
101
- navigator: Navigator;
102
- static?: boolean;
103
- }
104
- /**
105
- * Provides location context for the rest of the app.
106
- *
107
- * Note: You usually won't render a <Router> directly. Instead, you'll render a
108
- * router that is more specific to your environment such as a <BrowserRouter>
109
- * in web browsers or a <StaticRouter> for server rendering.
110
- *
111
- * @see https://reactrouter.com/docs/en/v6/api#router
112
- */
113
- export declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, }: RouterProps): React.ReactElement | null;
114
- export interface RoutesProps {
115
- children?: React.ReactNode;
116
- location?: Partial<Location> | string;
117
- }
118
- /**
119
- * A container for a nested tree of <Route> elements that renders the branch
120
- * that best matches the current location.
121
- *
122
- * @see https://reactrouter.com/docs/en/v6/api#routes
123
- */
124
- export declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
125
- /**
126
- * Returns the full href for the given "to" value. This is useful for building
127
- * custom links that are also accessible and preserve right-click behavior.
128
- *
129
- * @see https://reactrouter.com/docs/en/v6/api#usehref
130
- */
131
- export declare function useHref(to: To): string;
132
- /**
133
- * Returns true if this component is a descendant of a <Router>.
134
- *
135
- * @see https://reactrouter.com/docs/en/v6/api#useinroutercontext
136
- */
137
- export declare function useInRouterContext(): boolean;
138
- /**
139
- * Returns the current location object, which represents the current URL in web
140
- * browsers.
141
- *
142
- * Note: If you're using this it may mean you're doing some of your own
143
- * "routing" in your app, and we'd like to know what your use case is. We may
144
- * be able to provide something higher-level to better suit your needs.
145
- *
146
- * @see https://reactrouter.com/docs/en/v6/api#uselocation
147
- */
148
- export declare function useLocation(): Location;
149
- declare type ParamParseFailed = {
150
- failed: true;
151
- };
152
- declare type ParamParseSegment<Segment extends string> = Segment extends `${infer LeftSegment}/${infer RightSegment}` ? ParamParseSegment<LeftSegment> extends infer LeftResult ? ParamParseSegment<RightSegment> extends infer RightResult ? LeftResult extends string ? RightResult extends string ? LeftResult | RightResult : LeftResult : RightResult extends string ? RightResult : ParamParseFailed : ParamParseFailed : ParamParseSegment<RightSegment> extends infer RightResult ? RightResult extends string ? RightResult : ParamParseFailed : ParamParseFailed : Segment extends `:${infer Remaining}` ? Remaining : ParamParseFailed;
153
- declare type ParamParseKey<Segment extends string> = ParamParseSegment<Segment> extends string ? ParamParseSegment<Segment> : string;
154
- /**
155
- * Returns the current navigation action which describes how the router came to
156
- * the current location, either by a pop, push, or replace on the history stack.
157
- *
158
- * @see https://reactrouter.com/docs/en/v6/api#usenavigationtype
159
- */
160
- export declare function useNavigationType(): NavigationType;
161
- /**
162
- * Returns true if the URL for the given "to" value matches the current URL.
163
- * This is useful for components that need to know "active" state, e.g.
164
- * <NavLink>.
165
- *
166
- * @see https://reactrouter.com/docs/en/v6/api#usematch
167
- */
168
- export declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null;
169
- /**
170
- * The interface for the navigate() function returned from useNavigate().
171
- */
172
- export interface NavigateFunction {
173
- (to: To, options?: NavigateOptions): void;
174
- (delta: number): void;
175
- }
176
- export interface NavigateOptions {
177
- replace?: boolean;
178
- state?: any;
179
- }
180
- /**
181
- * Returns an imperative method for changing the location. Used by <Link>s, but
182
- * may also be used by other elements to change the location.
183
- *
184
- * @see https://reactrouter.com/docs/en/v6/api#usenavigate
185
- */
186
- export declare function useNavigate(): NavigateFunction;
187
- /**
188
- * Returns the context (if provided) for the child route at this level of the route
189
- * hierarchy.
190
- * @see https://reactrouter.com/docs/en/v6/api#useoutletcontext
191
- */
192
- export declare function useOutletContext<Context = unknown>(): Context;
193
- /**
194
- * Returns the element for the child route at this level of the route
195
- * hierarchy. Used internally by <Outlet> to render child routes.
196
- *
197
- * @see https://reactrouter.com/docs/en/v6/api#useoutlet
198
- */
199
- export declare function useOutlet(context?: unknown): React.ReactElement | null;
200
- /**
201
- * Returns an object of key/value pairs of the dynamic params from the current
202
- * URL that were matched by the route path.
203
- *
204
- * @see https://reactrouter.com/docs/en/v6/api#useparams
205
- */
206
- export declare function useParams<ParamsOrKey extends string | Record<string, string | undefined> = string>(): Readonly<[
207
- ParamsOrKey
208
- ] extends [string] ? Params<ParamsOrKey> : Partial<ParamsOrKey>>;
209
- /**
210
- * Resolves the pathname of the given `to` value against the current location.
211
- *
212
- * @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
213
- */
214
- export declare function useResolvedPath(to: To): Path;
215
- /**
216
- * Returns the element of the route that matched the current location, prepared
217
- * with the correct context to render the remainder of the route tree. Route
218
- * elements in the tree must render an <Outlet> to render their child route's
219
- * element.
220
- *
221
- * @see https://reactrouter.com/docs/en/v6/api#useroutes
222
- */
223
- export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
224
- /**
225
- * Creates a route config from a React "children" object, which is usually
226
- * either a `<Route>` element or an array of them. Used internally by
227
- * `<Routes>` to create a route config from its children.
228
- *
229
- * @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
230
- */
231
- export declare function createRoutesFromChildren(children: React.ReactNode): RouteObject[];
232
- /**
233
- * The parameters that were parsed from the URL path.
234
- */
235
- export declare type Params<Key extends string = string> = {
236
- readonly [key in Key]: string | undefined;
237
- };
238
- /**
239
- * A route object represents a logical route, with (optionally) its child
240
- * routes organized in a tree-like structure.
241
- */
242
- export interface RouteObject {
243
- caseSensitive?: boolean;
244
- children?: RouteObject[];
245
- element?: React.ReactNode;
246
- index?: boolean;
247
- path?: string;
248
- }
249
- /**
250
- * Returns a path with params interpolated.
251
- *
252
- * @see https://reactrouter.com/docs/en/v6/api#generatepath
253
- */
254
- export declare function generatePath(path: string, params?: Params): string;
255
- /**
256
- * A RouteMatch contains info about how a route matched a URL.
257
- */
258
- export interface RouteMatch<ParamKey extends string = string> {
259
- /**
260
- * The names and values of dynamic parameters in the URL.
261
- */
262
- params: Params<ParamKey>;
263
- /**
264
- * The portion of the URL pathname that was matched.
265
- */
266
- pathname: string;
267
- /**
268
- * The portion of the URL pathname that was matched before child routes.
269
- */
270
- pathnameBase: string;
271
- /**
272
- * The route object that was used to match.
273
- */
274
- route: RouteObject;
275
- }
276
- /**
277
- * Matches the given routes to a location and returns the match data.
278
- *
279
- * @see https://reactrouter.com/docs/en/v6/api#matchroutes
280
- */
281
- export declare function matchRoutes(routes: RouteObject[], locationArg: Partial<Location> | string, basename?: string): RouteMatch[] | null;
282
- /**
283
- * Renders the result of `matchRoutes()` into a React element.
284
- */
285
- export declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
286
- /**
287
- * A PathPattern is used to match on some portion of a URL pathname.
288
- */
289
- export interface PathPattern<Path extends string = string> {
290
- /**
291
- * A string to match against a URL pathname. May contain `:id`-style segments
292
- * to indicate placeholders for dynamic parameters. May also end with `/*` to
293
- * indicate matching the rest of the URL pathname.
294
- */
295
- path: Path;
296
- /**
297
- * Should be `true` if the static portions of the `path` should be matched in
298
- * the same case.
299
- */
300
- caseSensitive?: boolean;
301
- /**
302
- * Should be `true` if this pattern should match the entire URL pathname.
303
- */
304
- end?: boolean;
305
- }
306
- /**
307
- * A PathMatch contains info about how a PathPattern matched on a URL pathname.
308
- */
309
- export interface PathMatch<ParamKey extends string = string> {
310
- /**
311
- * The names and values of dynamic parameters in the URL.
312
- */
313
- params: Params<ParamKey>;
314
- /**
315
- * The portion of the URL pathname that was matched.
316
- */
317
- pathname: string;
318
- /**
319
- * The portion of the URL pathname that was matched before child routes.
320
- */
321
- pathnameBase: string;
322
- /**
323
- * The pattern that was used to match.
324
- */
325
- pattern: PathPattern;
326
- }
327
- /**
328
- * Performs pattern matching on a URL pathname and returns information about
329
- * the match.
330
- *
331
- * @see https://reactrouter.com/docs/en/v6/api#matchpath
332
- */
333
- export declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
334
- /**
335
- * Returns a resolved path object relative to the given pathname.
336
- *
337
- * @see https://reactrouter.com/docs/en/v6/api#resolvepath
338
- */
339
- export declare function resolvePath(to: To, fromPathname?: string): Path;
3
+ import type { MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps } from "./lib/components";
4
+ import { createRoutesFromChildren, renderMatches, MemoryRouter, Navigate, Outlet, Route, Router, Routes } from "./lib/components";
5
+ import type { Navigator } from "./lib/context";
6
+ import { LocationContext, NavigationContext, RouteContext } from "./lib/context";
7
+ import type { NavigateFunction, NavigateOptions } from "./lib/hooks";
8
+ import { useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes } from "./lib/hooks";
9
+ import type { Params, PathMatch, PathPattern, RouteMatch, RouteObject } from "./lib/router";
10
+ import { generatePath, matchPath, matchRoutes, resolvePath } from "./lib/router";
11
+ export type { Hash, IndexRouteProps, LayoutRouteProps, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, OutletProps, PathMatch, PathPattern, PathRouteProps, RouteMatch, RouteObject, RouteProps, RouterProps, RoutesProps, Navigator, Params, Path, Pathname, Search, To, };
12
+ export { MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createPath, createRoutesFromChildren, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, };
340
13
  /** @internal */
341
14
  export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, };