react-router 6.0.0-beta.6 → 6.0.1

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,6 +1,7 @@
1
1
  import * as React from "react";
2
- import { Action } from "history";
3
- import type { Blocker, History, InitialEntry, Location, Path, State, To } from "history";
2
+ import type { History, InitialEntry, Location, Path, To } from "history";
3
+ import { Action as NavigationType } from "history";
4
+ export type { Location, Path, To, NavigationType };
4
5
  /**
5
6
  * A Navigator is a "location changer"; it's how you get to different locations.
6
7
  *
@@ -10,7 +11,7 @@ import type { Blocker, History, InitialEntry, Location, Path, State, To } from "
10
11
  * to avoid "tearing" that may occur in a suspense-enabled app if the action
11
12
  * and/or location were to be read directly from the history instance.
12
13
  */
13
- export declare type Navigator = Omit<History, "action" | "location" | "back" | "forward" | "listen">;
14
+ export declare type Navigator = Omit<History, "action" | "location" | "back" | "forward" | "listen" | "block">;
14
15
  interface NavigationContextObject {
15
16
  basename: string;
16
17
  navigator: Navigator;
@@ -18,18 +19,15 @@ interface NavigationContextObject {
18
19
  }
19
20
  declare const NavigationContext: React.Context<NavigationContextObject>;
20
21
  interface LocationContextObject {
21
- action: Action;
22
22
  location: Location;
23
+ navigationType: NavigationType;
23
24
  }
24
25
  declare const LocationContext: React.Context<LocationContextObject>;
25
- interface RouteContextObject<ParamKey extends string = string> {
26
+ interface RouteContextObject {
26
27
  outlet: React.ReactElement | null;
27
- params: Readonly<Params<ParamKey>>;
28
- pathname: string;
29
- pathnameBase: string;
30
- route: RouteObject | null;
28
+ matches: RouteMatch[];
31
29
  }
32
- declare const RouteContext: React.Context<RouteContextObject<string>>;
30
+ declare const RouteContext: React.Context<RouteContextObject>;
33
31
  export interface MemoryRouterProps {
34
32
  basename?: string;
35
33
  children?: React.ReactNode;
@@ -39,13 +37,13 @@ export interface MemoryRouterProps {
39
37
  /**
40
38
  * A <Router> that stores all entries in memory.
41
39
  *
42
- * @see https://reactrouter.com/api/MemoryRouter
40
+ * @see https://reactrouter.com/docs/en/v6/api#memoryrouter
43
41
  */
44
42
  export declare function MemoryRouter({ basename, children, initialEntries, initialIndex }: MemoryRouterProps): React.ReactElement;
45
43
  export interface NavigateProps {
46
44
  to: To;
47
45
  replace?: boolean;
48
- state?: State;
46
+ state?: any;
49
47
  }
50
48
  /**
51
49
  * Changes the current location.
@@ -54,7 +52,7 @@ export interface NavigateProps {
54
52
  * able to use hooks. In functional components, we recommend you use the
55
53
  * `useNavigate` hook instead.
56
54
  *
57
- * @see https://reactrouter.com/api/Navigate
55
+ * @see https://reactrouter.com/docs/en/v6/api#navigate
58
56
  */
59
57
  export declare function Navigate({ to, replace, state }: NavigateProps): null;
60
58
  export interface OutletProps {
@@ -62,7 +60,7 @@ export interface OutletProps {
62
60
  /**
63
61
  * Renders the child route's element, if there is one.
64
62
  *
65
- * @see https://reactrouter.com/api/Outlet
63
+ * @see https://reactrouter.com/docs/en/v6/api#outlet
66
64
  */
67
65
  export declare function Outlet(_props: OutletProps): React.ReactElement | null;
68
66
  export interface RouteProps {
@@ -90,14 +88,14 @@ export interface IndexRouteProps {
90
88
  /**
91
89
  * Declares an element that should be rendered at a certain URL path.
92
90
  *
93
- * @see https://reactrouter.com/api/Route
91
+ * @see https://reactrouter.com/docs/en/v6/api#route
94
92
  */
95
93
  export declare function Route(_props: PathRouteProps | LayoutRouteProps | IndexRouteProps): React.ReactElement | null;
96
94
  export interface RouterProps {
97
- action?: Action;
98
95
  basename?: string;
99
96
  children?: React.ReactNode;
100
97
  location: Partial<Location> | string;
98
+ navigationType?: NavigationType;
101
99
  navigator: Navigator;
102
100
  static?: boolean;
103
101
  }
@@ -108,9 +106,9 @@ export interface RouterProps {
108
106
  * router that is more specific to your environment such as a <BrowserRouter>
109
107
  * in web browsers or a <StaticRouter> for server rendering.
110
108
  *
111
- * @see https://reactrouter.com/api/Router
109
+ * @see https://reactrouter.com/docs/en/v6/api#router
112
110
  */
113
- export declare function Router({ action, basename: basenameProp, children, location: locationProp, navigator, static: staticProp }: RouterProps): React.ReactElement | null;
111
+ export declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp }: RouterProps): React.ReactElement | null;
114
112
  export interface RoutesProps {
115
113
  children?: React.ReactNode;
116
114
  location?: Partial<Location> | string;
@@ -119,27 +117,20 @@ export interface RoutesProps {
119
117
  * A container for a nested tree of <Route> elements that renders the branch
120
118
  * that best matches the current location.
121
119
  *
122
- * @see https://reactrouter.com/api/Routes
120
+ * @see https://reactrouter.com/docs/en/v6/api#routes
123
121
  */
124
122
  export declare function Routes({ children, location }: RoutesProps): React.ReactElement | null;
125
- /**
126
- * Blocks all navigation attempts. This is useful for preventing the page from
127
- * changing until some condition is met, like saving form data.
128
- *
129
- * @see https://reactrouter.com/api/useBlocker
130
- */
131
- export declare function useBlocker(blocker: Blocker, when?: boolean): void;
132
123
  /**
133
124
  * Returns the full href for the given "to" value. This is useful for building
134
125
  * custom links that are also accessible and preserve right-click behavior.
135
126
  *
136
- * @see https://reactrouter.com/api/useHref
127
+ * @see https://reactrouter.com/docs/en/v6/api#usehref
137
128
  */
138
129
  export declare function useHref(to: To): string;
139
130
  /**
140
131
  * Returns true if this component is a descendant of a <Router>.
141
132
  *
142
- * @see https://reactrouter.com/api/useInRouterContext
133
+ * @see https://reactrouter.com/docs/en/v6/api#useinroutercontext
143
134
  */
144
135
  export declare function useInRouterContext(): boolean;
145
136
  /**
@@ -150,15 +141,22 @@ export declare function useInRouterContext(): boolean;
150
141
  * "routing" in your app, and we'd like to know what your use case is. We may
151
142
  * be able to provide something higher-level to better suit your needs.
152
143
  *
153
- * @see https://reactrouter.com/api/useLocation
144
+ * @see https://reactrouter.com/docs/en/v6/api#uselocation
154
145
  */
155
146
  export declare function useLocation(): Location;
147
+ /**
148
+ * Returns the current navigation action which describes how the router came to
149
+ * the current location, either by a pop, push, or replace on the history stack.
150
+ *
151
+ * @see https://reactrouter.com/docs/en/v6/api#usenavigationtype
152
+ */
153
+ export declare function useNavigationType(): NavigationType;
156
154
  /**
157
155
  * Returns true if the URL for the given "to" value matches the current URL.
158
156
  * This is useful for components that need to know "active" state, e.g.
159
157
  * <NavLink>.
160
158
  *
161
- * @see https://reactrouter.com/api/useMatch
159
+ * @see https://reactrouter.com/docs/en/v6/api#usematch
162
160
  */
163
161
  export declare function useMatch<ParamKey extends string = string>(pattern: PathPattern | string): PathMatch<ParamKey> | null;
164
162
  /**
@@ -170,33 +168,33 @@ export interface NavigateFunction {
170
168
  }
171
169
  export interface NavigateOptions {
172
170
  replace?: boolean;
173
- state?: State;
171
+ state?: any;
174
172
  }
175
173
  /**
176
174
  * Returns an imperative method for changing the location. Used by <Link>s, but
177
175
  * may also be used by other elements to change the location.
178
176
  *
179
- * @see https://reactrouter.com/api/useNavigate
177
+ * @see https://reactrouter.com/docs/en/v6/api#usenavigate
180
178
  */
181
179
  export declare function useNavigate(): NavigateFunction;
182
180
  /**
183
181
  * Returns the element for the child route at this level of the route
184
182
  * hierarchy. Used internally by <Outlet> to render child routes.
185
183
  *
186
- * @see https://reactrouter.com/api/useOutlet
184
+ * @see https://reactrouter.com/docs/en/v6/api#useoutlet
187
185
  */
188
186
  export declare function useOutlet(): React.ReactElement | null;
189
187
  /**
190
188
  * Returns an object of key/value pairs of the dynamic params from the current
191
189
  * URL that were matched by the route path.
192
190
  *
193
- * @see https://reactrouter.com/api/useParams
191
+ * @see https://reactrouter.com/docs/en/v6/api#useparams
194
192
  */
195
193
  export declare function useParams<Key extends string = string>(): Readonly<Params<Key>>;
196
194
  /**
197
195
  * Resolves the pathname of the given `to` value against the current location.
198
196
  *
199
- * @see https://reactrouter.com/api/useResolvedPath
197
+ * @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
200
198
  */
201
199
  export declare function useResolvedPath(to: To): Path;
202
200
  /**
@@ -205,7 +203,7 @@ export declare function useResolvedPath(to: To): Path;
205
203
  * elements in the tree must render an <Outlet> to render their child route's
206
204
  * element.
207
205
  *
208
- * @see https://reactrouter.com/api/useRoutes
206
+ * @see https://reactrouter.com/docs/en/v6/api#useroutes
209
207
  */
210
208
  export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
211
209
  /**
@@ -213,7 +211,7 @@ export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<L
213
211
  * either a `<Route>` element or an array of them. Used internally by
214
212
  * `<Routes>` to create a route config from its children.
215
213
  *
216
- * @see https://reactrouter.com/api/createRoutesFromChildren
214
+ * @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
217
215
  */
218
216
  export declare function createRoutesFromChildren(children: React.ReactNode): RouteObject[];
219
217
  /**
@@ -236,7 +234,7 @@ export interface RouteObject {
236
234
  /**
237
235
  * Returns a path with params interpolated.
238
236
  *
239
- * @see https://reactrouter.com/api/generatePath
237
+ * @see https://reactrouter.com/docs/en/v6/api#generatepath
240
238
  */
241
239
  export declare function generatePath(path: string, params?: Params): string;
242
240
  /**
@@ -263,7 +261,7 @@ export interface RouteMatch<ParamKey extends string = string> {
263
261
  /**
264
262
  * Matches the given routes to a location and returns the match data.
265
263
  *
266
- * @see https://reactrouter.com/api/matchRoutes
264
+ * @see https://reactrouter.com/docs/en/v6/api#matchroutes
267
265
  */
268
266
  export declare function matchRoutes(routes: RouteObject[], locationArg: Partial<Location> | string, basename?: string): RouteMatch[] | null;
269
267
  /**
@@ -315,13 +313,13 @@ export interface PathMatch<ParamKey extends string = string> {
315
313
  * Performs pattern matching on a URL pathname and returns information about
316
314
  * the match.
317
315
  *
318
- * @see https://reactrouter.com/api/matchPath
316
+ * @see https://reactrouter.com/docs/en/v6/api#matchpath
319
317
  */
320
318
  export declare function matchPath<ParamKey extends string = string>(pattern: PathPattern | string, pathname: string): PathMatch<ParamKey> | null;
321
319
  /**
322
320
  * Returns a resolved path object relative to the given pathname.
323
321
  *
324
- * @see https://reactrouter.com/api/resolvePath
322
+ * @see https://reactrouter.com/docs/en/v6/api#resolvepath
325
323
  */
326
324
  export declare function resolvePath(to: To, fromPathname?: string): Path;
327
325
  /** @internal */