@remix-run/router 1.9.0-pre.1 → 1.9.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/CHANGELOG.md +6 -12
- package/dist/history.d.ts +4 -4
- package/dist/router.cjs.js +12 -11
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +8 -8
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +12 -11
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +1 -1
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +9 -9
- package/history.ts +5 -5
- package/package.json +1 -1
- package/utils.ts +24 -17
package/dist/utils.d.ts
CHANGED
|
@@ -119,12 +119,12 @@ interface DataFunctionArgs<Context> {
|
|
|
119
119
|
/**
|
|
120
120
|
* Arguments passed to loader functions
|
|
121
121
|
*/
|
|
122
|
-
export interface LoaderFunctionArgs<
|
|
122
|
+
export interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* Arguments passed to action functions
|
|
126
126
|
*/
|
|
127
|
-
export interface ActionFunctionArgs<
|
|
127
|
+
export interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
130
|
* Loaders and actions can return anything except `undefined` (`null` is a
|
|
@@ -135,14 +135,14 @@ type DataFunctionValue = Response | NonNullable<unknown> | null;
|
|
|
135
135
|
/**
|
|
136
136
|
* Route loader function signature
|
|
137
137
|
*/
|
|
138
|
-
export interface LoaderFunction<
|
|
139
|
-
(args: LoaderFunctionArgs<
|
|
138
|
+
export interface LoaderFunction<Context = any> {
|
|
139
|
+
(args: LoaderFunctionArgs<Context>): Promise<DataFunctionValue> | DataFunctionValue;
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* Route action function signature
|
|
143
143
|
*/
|
|
144
|
-
export interface ActionFunction<
|
|
145
|
-
(args: ActionFunctionArgs<
|
|
144
|
+
export interface ActionFunction<Context = any> {
|
|
145
|
+
(args: ActionFunctionArgs<Context>): Promise<DataFunctionValue> | DataFunctionValue;
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Arguments passed to shouldRevalidate function
|
|
@@ -301,12 +301,12 @@ export declare function convertRoutesToDataRoutes(routes: AgnosticRouteObject[],
|
|
|
301
301
|
* @see https://reactrouter.com/utils/match-routes
|
|
302
302
|
*/
|
|
303
303
|
export declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
|
|
304
|
-
export interface UIMatch<
|
|
304
|
+
export interface UIMatch<Data = unknown, Handle = unknown> {
|
|
305
305
|
id: string;
|
|
306
306
|
pathname: string;
|
|
307
307
|
params: AgnosticRouteMatch["params"];
|
|
308
|
-
data:
|
|
309
|
-
handle:
|
|
308
|
+
data: Data;
|
|
309
|
+
handle: Handle;
|
|
310
310
|
}
|
|
311
311
|
export declare function convertRouteMatchToUiMatch(match: AgnosticDataRouteMatch, loaderData: RouteData): UIMatch;
|
|
312
312
|
/**
|
package/history.ts
CHANGED
|
@@ -56,11 +56,11 @@ export interface Path {
|
|
|
56
56
|
* An entry in a history stack. A location contains information about the
|
|
57
57
|
* URL path, as well as possibly some arbitrary state and a key.
|
|
58
58
|
*/
|
|
59
|
-
export interface Location<
|
|
59
|
+
export interface Location<State = any> extends Path {
|
|
60
60
|
/**
|
|
61
61
|
* A value of arbitrary data associated with this location.
|
|
62
62
|
*/
|
|
63
|
-
state:
|
|
63
|
+
state: State;
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* A unique string associated with this location. May be used to safely store
|
|
@@ -100,8 +100,8 @@ export interface Listener {
|
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Describes a location that is the destination of some navigation, either via
|
|
103
|
-
* `history.push` or `history.replace`.
|
|
104
|
-
* URL path.
|
|
103
|
+
* `history.push` or `history.replace`. This may be either a URL or the pieces
|
|
104
|
+
* of a URL path.
|
|
105
105
|
*/
|
|
106
106
|
export type To = string | Partial<Path>;
|
|
107
107
|
|
|
@@ -503,7 +503,7 @@ export function warning(cond: any, message: string) {
|
|
|
503
503
|
try {
|
|
504
504
|
// Welcome to debugging history!
|
|
505
505
|
//
|
|
506
|
-
// This error is thrown as a convenience so you can more easily
|
|
506
|
+
// This error is thrown as a convenience, so you can more easily
|
|
507
507
|
// find the source for a warning that appears in the console by
|
|
508
508
|
// enabling "pause on exceptions" in your JavaScript debugger.
|
|
509
509
|
throw new Error(message);
|
package/package.json
CHANGED
package/utils.ts
CHANGED
|
@@ -145,16 +145,19 @@ interface DataFunctionArgs<Context> {
|
|
|
145
145
|
|
|
146
146
|
// TODO: (v7) Change the defaults from any to unknown in and remove Remix wrappers:
|
|
147
147
|
// ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs
|
|
148
|
+
// Also, make them a type alias instead of an interface
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* Arguments passed to loader functions
|
|
151
152
|
*/
|
|
152
|
-
export interface LoaderFunctionArgs<
|
|
153
|
+
export interface LoaderFunctionArgs<Context = any>
|
|
154
|
+
extends DataFunctionArgs<Context> {}
|
|
153
155
|
|
|
154
156
|
/**
|
|
155
157
|
* Arguments passed to action functions
|
|
156
158
|
*/
|
|
157
|
-
export interface ActionFunctionArgs<
|
|
159
|
+
export interface ActionFunctionArgs<Context = any>
|
|
160
|
+
extends DataFunctionArgs<Context> {}
|
|
158
161
|
|
|
159
162
|
/**
|
|
160
163
|
* Loaders and actions can return anything except `undefined` (`null` is a
|
|
@@ -166,15 +169,19 @@ type DataFunctionValue = Response | NonNullable<unknown> | null;
|
|
|
166
169
|
/**
|
|
167
170
|
* Route loader function signature
|
|
168
171
|
*/
|
|
169
|
-
export interface LoaderFunction<
|
|
170
|
-
(args: LoaderFunctionArgs<
|
|
172
|
+
export interface LoaderFunction<Context = any> {
|
|
173
|
+
(args: LoaderFunctionArgs<Context>):
|
|
174
|
+
| Promise<DataFunctionValue>
|
|
175
|
+
| DataFunctionValue;
|
|
171
176
|
}
|
|
172
177
|
|
|
173
178
|
/**
|
|
174
179
|
* Route action function signature
|
|
175
180
|
*/
|
|
176
|
-
export interface ActionFunction<
|
|
177
|
-
(args: ActionFunctionArgs<
|
|
181
|
+
export interface ActionFunction<Context = any> {
|
|
182
|
+
(args: ActionFunctionArgs<Context>):
|
|
183
|
+
| Promise<DataFunctionValue>
|
|
184
|
+
| DataFunctionValue;
|
|
178
185
|
}
|
|
179
186
|
|
|
180
187
|
/**
|
|
@@ -353,10 +360,10 @@ type PathParam<Path extends string> =
|
|
|
353
360
|
_PathParam<Path>;
|
|
354
361
|
|
|
355
362
|
// Attempt to parse the given string segment. If it fails, then just return the
|
|
356
|
-
// plain string type as a default fallback. Otherwise return the union of the
|
|
363
|
+
// plain string type as a default fallback. Otherwise, return the union of the
|
|
357
364
|
// parsed string literals that were referenced as dynamic segments in the route.
|
|
358
365
|
export type ParamParseKey<Segment extends string> =
|
|
359
|
-
// if could not find path params, fallback to `string`
|
|
366
|
+
// if you could not find path params, fallback to `string`
|
|
360
367
|
[PathParam<Segment>] extends [never] ? string : PathParam<Segment>;
|
|
361
368
|
|
|
362
369
|
/**
|
|
@@ -400,7 +407,7 @@ function isIndexRoute(
|
|
|
400
407
|
return route.index === true;
|
|
401
408
|
}
|
|
402
409
|
|
|
403
|
-
// Walk the route tree generating unique IDs where necessary so we are working
|
|
410
|
+
// Walk the route tree generating unique IDs where necessary, so we are working
|
|
404
411
|
// solely with AgnosticDataRouteObject's within the Router
|
|
405
412
|
export function convertRoutesToDataRoutes(
|
|
406
413
|
routes: AgnosticRouteObject[],
|
|
@@ -493,12 +500,12 @@ export function matchRoutes<
|
|
|
493
500
|
return matches;
|
|
494
501
|
}
|
|
495
502
|
|
|
496
|
-
export interface UIMatch<
|
|
503
|
+
export interface UIMatch<Data = unknown, Handle = unknown> {
|
|
497
504
|
id: string;
|
|
498
505
|
pathname: string;
|
|
499
506
|
params: AgnosticRouteMatch["params"];
|
|
500
|
-
data:
|
|
501
|
-
handle:
|
|
507
|
+
data: Data;
|
|
508
|
+
handle: Handle;
|
|
502
509
|
}
|
|
503
510
|
|
|
504
511
|
export function convertRouteMatchToUiMatch(
|
|
@@ -567,7 +574,7 @@ function flattenRoutes<
|
|
|
567
574
|
let path = joinPaths([parentPath, meta.relativePath]);
|
|
568
575
|
let routesMeta = parentsMeta.concat(meta);
|
|
569
576
|
|
|
570
|
-
// Add the children before adding this route to the array so we traverse the
|
|
577
|
+
// Add the children before adding this route to the array, so we traverse the
|
|
571
578
|
// route tree depth-first and child routes appear before their parents in
|
|
572
579
|
// the "flattened" version.
|
|
573
580
|
if (route.children && route.children.length > 0) {
|
|
@@ -644,10 +651,10 @@ function explodeOptionalSegments(path: string): string[] {
|
|
|
644
651
|
let result: string[] = [];
|
|
645
652
|
|
|
646
653
|
// All child paths with the prefix. Do this for all children before the
|
|
647
|
-
// optional version for all children so we get consistent ordering where the
|
|
654
|
+
// optional version for all children, so we get consistent ordering where the
|
|
648
655
|
// parent optional aspect is preferred as required. Otherwise, we can get
|
|
649
656
|
// child sections interspersed where deeper optional segments are higher than
|
|
650
|
-
// parent optional segments, where for example, /:two would
|
|
657
|
+
// parent optional segments, where for example, /:two would explode _earlier_
|
|
651
658
|
// then /:one. By always including the parent as required _for all children_
|
|
652
659
|
// first, we avoid this issue
|
|
653
660
|
result.push(
|
|
@@ -656,7 +663,7 @@ function explodeOptionalSegments(path: string): string[] {
|
|
|
656
663
|
)
|
|
657
664
|
);
|
|
658
665
|
|
|
659
|
-
// Then if this is an optional value, add all child versions without
|
|
666
|
+
// Then, if this is an optional value, add all child versions without
|
|
660
667
|
if (isOptional) {
|
|
661
668
|
result.push(...restExploded);
|
|
662
669
|
}
|
|
@@ -972,7 +979,7 @@ function compilePath(
|
|
|
972
979
|
regexpSource += "\\/*$";
|
|
973
980
|
} else if (path !== "" && path !== "/") {
|
|
974
981
|
// If our path is non-empty and contains anything beyond an initial slash,
|
|
975
|
-
// then we have _some_ form of path in our regex so we should expect to
|
|
982
|
+
// then we have _some_ form of path in our regex, so we should expect to
|
|
976
983
|
// match only if we find the end of this path segment. Look for an optional
|
|
977
984
|
// non-captured trailing slash (to match a portion of the URL) or the end
|
|
978
985
|
// of the path (if we've matched to the end). We used to do this with a
|