react-router 0.0.0-experimental-b1ff171f → 0.0.0-experimental-12346

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.
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) React Training 2016-2019
3
+ Copyright (c) React Training 2015-2019
4
+ Copyright (c) Remix Software 2020-2021
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # React Router
2
2
 
3
- The `react-router` package is the heart of [React Router](/) and provides all
3
+ The `react-router` package is the heart of [React Router](https://github.com/remix-run/react-router) and provides all
4
4
  the core functionality for both
5
- [`react-router-dom`](https://github.com/ReactTraining/react-router/packages/react-router-dom)
5
+ [`react-router-dom`](/packages/react-router-dom)
6
6
  and
7
- [`react-router-native`](https://github.com/ReactTraining/react-router/packages/react-router-native).
7
+ [`react-router-native`](/packages/react-router-native).
8
8
 
9
9
  If you're using React Router, you should never `import` anything directly from
10
10
  the `react-router` package, but you should have everything you need in either
package/index.d.ts CHANGED
@@ -1,284 +1,14 @@
1
- import * as React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Action, Path, State, LocationPieces, Location, Blocker, To, History, InitialEntry } from 'history';
4
- /**
5
- * A Navigator is a "location changer"; it's how you get to different locations.
6
- *
7
- * Every history instance conforms to the Navigator interface, but the
8
- * distinction is useful primarily when it comes to the low-level <Router> API
9
- * where both the location and a navigator must be provided separately in order
10
- * to avoid "tearing" that may occur in a suspense-enabled app if the action
11
- * and/or location were to be read directly from the history instance.
12
- */
13
- export declare type Navigator = Omit<History, 'action' | 'location' | 'back' | 'forward' | 'listen'>;
14
- /**
15
- * A <Router> that stores all entries in memory.
16
- */
17
- export declare function MemoryRouter({ children, initialEntries, initialIndex, timeoutMs }: MemoryRouterProps): React.ReactElement;
18
- export declare namespace MemoryRouter {
19
- var displayName: string;
20
- var propTypes: {
21
- children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
22
- initialEntries: PropTypes.Requireable<(string | PropTypes.InferProps<{
23
- pathname: PropTypes.Requireable<string>;
24
- search: PropTypes.Requireable<string>;
25
- hash: PropTypes.Requireable<string>;
26
- state: PropTypes.Requireable<object>;
27
- key: PropTypes.Requireable<string>;
28
- }> | null | undefined)[]>;
29
- initialIndex: PropTypes.Requireable<number>;
30
- timeoutMs: PropTypes.Requireable<number>;
31
- };
32
- }
33
- export interface MemoryRouterProps {
34
- children?: React.ReactNode;
35
- initialEntries?: InitialEntry[];
36
- initialIndex?: number;
37
- timeoutMs?: number;
38
- }
39
- /**
40
- * Navigate programmatically using a component.
41
- */
42
- export declare function Navigate({ to, replace, state }: NavigateProps): null;
43
- export declare namespace Navigate {
44
- var displayName: string;
45
- var propTypes: {
46
- to: PropTypes.Validator<string | PropTypes.InferProps<{
47
- pathname: PropTypes.Requireable<string>;
48
- search: PropTypes.Requireable<string>;
49
- hash: PropTypes.Requireable<string>;
50
- }>>;
51
- replace: PropTypes.Requireable<boolean>;
52
- state: PropTypes.Requireable<object>;
53
- };
54
- }
55
- export interface NavigateProps {
56
- to: To;
57
- replace?: boolean;
58
- state?: State;
59
- }
60
- /**
61
- * Renders the child route's element, if there is one.
62
- */
63
- export declare function Outlet(): React.ReactElement | null;
64
- export declare namespace Outlet {
65
- var displayName: string;
66
- var propTypes: {};
67
- }
68
- export interface OutletProps {
69
- }
70
- /**
71
- * Used in a route config to render an element.
72
- */
73
- export declare function Route({ element }: RouteProps): React.ReactElement | null;
74
- export declare namespace Route {
75
- var displayName: string;
76
- var propTypes: {
77
- caseSensitive: PropTypes.Requireable<boolean>;
78
- children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
79
- element: PropTypes.Requireable<PropTypes.ReactElementLike>;
80
- path: PropTypes.Requireable<string>;
81
- };
82
- }
83
- export interface RouteProps {
84
- caseSensitive?: boolean;
85
- children?: React.ReactNode;
86
- element?: React.ReactElement | null;
87
- path?: string;
88
- }
89
- /**
90
- * The low-level root context provider in a React Router app. You usually won't
91
- * render a <Router> directly. Instead, you'll render a router that is more
92
- * specific to your environment such as a <BrowserRouter> in web browsers or a
93
- * <StaticRouter> for server rendering.
94
- */
95
- export declare function Router({ children, action, location, navigator, pending, static: staticProp }: RouterProps): React.ReactElement;
96
- export declare namespace Router {
97
- var displayName: string;
98
- var propTypes: {
99
- children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
100
- action: PropTypes.Requireable<string>;
101
- location: PropTypes.Validator<object>;
102
- navigator: PropTypes.Validator<PropTypes.InferProps<{
103
- createHref: PropTypes.Validator<(...args: any[]) => any>;
104
- push: PropTypes.Validator<(...args: any[]) => any>;
105
- replace: PropTypes.Validator<(...args: any[]) => any>;
106
- go: PropTypes.Validator<(...args: any[]) => any>;
107
- block: PropTypes.Validator<(...args: any[]) => any>;
108
- }>>;
109
- pending: PropTypes.Requireable<boolean>;
110
- static: PropTypes.Requireable<boolean>;
111
- };
112
- }
113
- export interface RouterProps {
114
- children?: React.ReactNode;
115
- action?: Action;
116
- location: Location;
117
- navigator: Navigator;
118
- pending?: boolean;
119
- static?: boolean;
120
- }
121
- /**
122
- * A container for a nested tree of <Route> elements that renders the branch
123
- * that best matches the current location.
124
- */
125
- export declare function Routes({ basename, children }: RoutesProps): React.ReactElement | null;
126
- export declare namespace Routes {
127
- var displayName: string;
128
- var propTypes: {
129
- basename: PropTypes.Requireable<string>;
130
- children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
131
- };
132
- }
133
- export interface RoutesProps {
134
- basename?: string;
135
- children?: React.ReactNode;
136
- }
137
- /**
138
- * Blocks all navigation attempts. This is useful for preventing the page from
139
- * changing until some condition is met, like saving form data.
140
- */
141
- export declare function useBlocker(blocker: Blocker, when?: boolean): void;
142
- /**
143
- * Returns the full href for the given "to" value. This is useful for building
144
- * custom links that are also accessible and preserve right-click behavior.
145
- */
146
- export declare function useHref(to: To): string;
147
- /**
148
- * Returns true if this component is a descendant of a <Router>.
149
- */
150
- export declare function useInRouterContext(): boolean;
151
- /**
152
- * Returns the current location object, which represents the current URL in web
153
- * browsers.
154
- *
155
- * NOTE: If you're using this it may mean you're doing some of your own
156
- * "routing" in your app, and we'd like to know what your use case is. We may be
157
- * able to provide something higher-level to better suit your needs.
158
- */
159
- export declare function useLocation(): Location;
160
- /**
161
- * Returns true if the router is pending a location update.
162
- */
163
- export declare function useLocationPending(): boolean;
164
- /**
165
- * Returns true if the URL for the given "to" value matches the current URL.
166
- * This is useful for components that need to know "active" state, e.g.
167
- * <NavLink>.
168
- */
169
- export declare function useMatch(path: PathPattern): PathMatch | null;
170
- declare type PathPattern = string | {
171
- path: string;
172
- caseSensitive?: boolean;
173
- end?: boolean;
174
- };
175
- /**
176
- * The interface for the navigate() function returned from useNavigate().
177
- */
178
- export interface NavigateFunction {
179
- (delta: number): void;
180
- (to: To, options?: {
181
- replace?: boolean;
182
- state?: State;
183
- }): void;
184
- }
185
- /**
186
- * Returns an imperative method for changing the location. Used by <Link>s, but
187
- * may also be used by other elements to change the location.
188
- */
189
- export declare function useNavigate(): NavigateFunction;
190
- /**
191
- * Returns the outlet element at this level of the route hierarchy. Used to
192
- * render child routes.
193
- */
194
- export declare function useOutlet(): React.ReactElement | null;
195
- /**
196
- * Returns a hash of the dynamic params that were matched in the route path.
197
- * This is useful for using ids embedded in the URL to fetch data, but we
198
- * eventually want to provide something at a higher level for this.
199
- */
200
- export declare function useParams(): Params;
201
- /**
202
- * Returns a fully-resolved location object relative to the current location.
203
- */
204
- export declare function useResolvedLocation(to: To): ResolvedLocation;
205
- /**
206
- * Returns the element of the route that matched the current location, prepared
207
- * with the correct context to render the remainder of the route tree. Route
208
- * elements in the tree must render an <Outlet> to render their child route's
209
- * element.
210
- */
211
- export declare function useRoutes(partialRoutes: PartialRouteObject[], basename?: string): React.ReactElement | null;
212
- /**
213
- * Creates a routes config object from an array of {@link PartialRouteObject}
214
- * objects.
215
- */
216
- export declare function createRoutesFromArray(array: PartialRouteObject[]): RouteObject[];
217
- /**
218
- * Creates a routes config object from a React "children" object, which is
219
- * usually either a {@link Route | `<Route>`} element (with its children) or an
220
- * array of them.
221
- */
222
- export declare function createRoutesFromChildren(children: React.ReactNode): RouteObject[];
223
- /**
224
- * A function that will be called when the router is about to render the
225
- * associated route. This function usually kicks off a fetch or similar
226
- * operation that primes a local data cache for retrieval while rendering later.
227
- */
228
- declare type RoutePreloadFunction = (params: Params, location: Location, index: number) => void;
229
- /**
230
- * A "partial route" object is usually supplied by the user and may omit certain
231
- * properties of a real route object such as `path` and `element`, which have
232
- * reasonable defaults.
233
- */
234
- export interface PartialRouteObject {
235
- path?: string;
236
- caseSensitive?: boolean;
237
- element?: React.ReactNode;
238
- preload?: RoutePreloadFunction;
239
- children?: PartialRouteObject[];
240
- }
241
- /**
242
- * A route object represents a logical route, with (optionally) its child routes
243
- * organized in a tree-like structure.
244
- */
245
- export interface RouteObject {
246
- path: string;
247
- caseSensitive: boolean;
248
- element: React.ReactNode;
249
- preload?: RoutePreloadFunction;
250
- children?: RouteObject[];
251
- }
252
- /**
253
- * Creates a path with params interpolated.
254
- */
255
- export declare function generatePath(pathname: string, params?: Params): string;
256
- /**
257
- * The parameters that were parsed from the URL path.
258
- */
259
- export declare type Params = Record<string, string>;
260
- /**
261
- * Matches the given routes to a location and returns the match data.
262
- */
263
- export declare function matchRoutes(routes: RouteObject[], location: Path | LocationPieces, basename?: string): RouteMatch[] | null;
264
- export interface RouteMatch {
265
- route: RouteObject;
266
- pathname: string;
267
- params: Params;
268
- }
269
- /**
270
- * Performs pattern matching on a URL pathname and returns information about the
271
- * match.
272
- */
273
- export declare function matchPath(pattern: PathPattern, pathname: string): PathMatch | null;
274
- export interface PathMatch {
275
- path: string;
276
- pathname: string;
277
- params: Params;
278
- }
279
- /**
280
- * Returns a fully resolved location object relative to the given pathname.
281
- */
282
- export declare function resolveLocation(to: To, fromPathname?: string): ResolvedLocation;
283
- export declare type ResolvedLocation = Omit<Location, 'state' | 'key'>;
284
- export {};
1
+ import type { Hash, Location, Path, Pathname, Search, To } from "history";
2
+ import { Action as NavigationType, parsePath, createPath } from "history";
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, };
13
+ /** @internal */
14
+ export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, };