@remix-run/router 0.0.0-experimental-c9f8a7b2 → 0.0.0-experimental-e960cf1a
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 +8 -199
- package/dist/index.d.ts +2 -2
- package/dist/router.cjs.js +138 -90
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +3 -2
- package/dist/router.js +135 -91
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +138 -90
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +13 -0
- package/index.ts +5 -0
- package/package.json +1 -1
- package/router.ts +243 -124
- package/utils.ts +25 -9
package/utils.ts
CHANGED
|
@@ -223,6 +223,17 @@ export interface DetectErrorBoundaryFunction {
|
|
|
223
223
|
(route: AgnosticRouteObject): boolean;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
export interface DataStrategyFunctionArgs {
|
|
227
|
+
request: Request;
|
|
228
|
+
matches: AgnosticDataStrategyMatch[];
|
|
229
|
+
type: "loader" | "action";
|
|
230
|
+
defaultStrategy(match: AgnosticDataStrategyMatch): Promise<DataResult>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface DataStrategyFunction {
|
|
234
|
+
(args: DataStrategyFunctionArgs): Promise<DataResult[]>;
|
|
235
|
+
}
|
|
236
|
+
|
|
226
237
|
/**
|
|
227
238
|
* Function provided by the framework-aware layers to set any framework-specific
|
|
228
239
|
* properties from framework-agnostic properties
|
|
@@ -401,6 +412,14 @@ export interface AgnosticRouteMatch<
|
|
|
401
412
|
export interface AgnosticDataRouteMatch
|
|
402
413
|
extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {}
|
|
403
414
|
|
|
415
|
+
export type LazyRoutePromise = PromiseLike<AgnosticDataRouteObject> &
|
|
416
|
+
AgnosticDataRouteObject;
|
|
417
|
+
|
|
418
|
+
export interface AgnosticDataStrategyMatch
|
|
419
|
+
extends Omit<AgnosticRouteMatch<string, AgnosticDataRouteObject>, "route"> {
|
|
420
|
+
route: LazyRoutePromise;
|
|
421
|
+
}
|
|
422
|
+
|
|
404
423
|
function isIndexRoute(
|
|
405
424
|
route: AgnosticRouteObject
|
|
406
425
|
): route is AgnosticIndexRouteObject {
|
|
@@ -685,7 +704,7 @@ function rankRouteBranches(branches: RouteBranch[]): void {
|
|
|
685
704
|
);
|
|
686
705
|
}
|
|
687
706
|
|
|
688
|
-
const paramRe =
|
|
707
|
+
const paramRe = /^:\w+$/;
|
|
689
708
|
const dynamicSegmentValue = 3;
|
|
690
709
|
const indexRouteValue = 2;
|
|
691
710
|
const emptySegmentValue = 1;
|
|
@@ -822,7 +841,7 @@ export function generatePath<Path extends string>(
|
|
|
822
841
|
return stringify(params[star]);
|
|
823
842
|
}
|
|
824
843
|
|
|
825
|
-
const keyMatch = segment.match(/^:(
|
|
844
|
+
const keyMatch = segment.match(/^:(\w+)(\??)$/);
|
|
826
845
|
if (keyMatch) {
|
|
827
846
|
const [, key, optional] = keyMatch;
|
|
828
847
|
let param = params[key as PathParam<Path>];
|
|
@@ -967,13 +986,10 @@ function compilePath(
|
|
|
967
986
|
.replace(/\/*\*?$/, "") // Ignore trailing / and /*, we'll handle it below
|
|
968
987
|
.replace(/^\/*/, "/") // Make sure it has a leading /
|
|
969
988
|
.replace(/[\\.*+^${}|()[\]]/g, "\\$&") // Escape special regex chars
|
|
970
|
-
.replace(
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
|
|
975
|
-
}
|
|
976
|
-
);
|
|
989
|
+
.replace(/\/:(\w+)(\?)?/g, (_: string, paramName: string, isOptional) => {
|
|
990
|
+
params.push({ paramName, isOptional: isOptional != null });
|
|
991
|
+
return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
|
|
992
|
+
});
|
|
977
993
|
|
|
978
994
|
if (path.endsWith("*")) {
|
|
979
995
|
params.push({ paramName: "*" });
|