@remix-run/router 0.0.0-experimental-8bb3ffdf → 0.0.0-experimental-d90c8fb3
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 +19 -9
- package/dist/router.cjs.js +14 -18
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +14 -18
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +14 -18
- 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/package.json +1 -1
- package/router.ts +5 -1
- package/utils.ts +23 -34
package/dist/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v0.0.0-experimental-
|
|
2
|
+
* @remix-run/router v0.0.0-experimental-d90c8fb3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -523,14 +523,14 @@ function matchRoutes(routes, locationArg, basename) {
|
|
|
523
523
|
rankRouteBranches(branches);
|
|
524
524
|
let matches = null;
|
|
525
525
|
for (let i = 0; matches == null && i < branches.length; ++i) {
|
|
526
|
-
matches = matchRouteBranch(branches[i],
|
|
527
526
|
// Incoming pathnames are generally encoded from either window.location
|
|
528
527
|
// or from router.navigate, but we want to match against the unencoded
|
|
529
528
|
// paths in the route definitions. Memory router locations won't be
|
|
530
529
|
// encoded here but there also shouldn't be anything to decode so this
|
|
531
530
|
// should be a safe operation. This avoids needing matchRoutes to be
|
|
532
531
|
// history-aware.
|
|
533
|
-
|
|
532
|
+
let decoded = decodePath(pathname);
|
|
533
|
+
matches = matchRouteBranch(branches[i], decoded);
|
|
534
534
|
}
|
|
535
535
|
return matches;
|
|
536
536
|
}
|
|
@@ -653,7 +653,7 @@ function rankRouteBranches(branches) {
|
|
|
653
653
|
branches.sort((a, b) => a.score !== b.score ? b.score - a.score // Higher score first
|
|
654
654
|
: compareIndexes(a.routesMeta.map(meta => meta.childrenIndex), b.routesMeta.map(meta => meta.childrenIndex)));
|
|
655
655
|
}
|
|
656
|
-
const paramRe =
|
|
656
|
+
const paramRe = /^:[\w-]+$/;
|
|
657
657
|
const dynamicSegmentValue = 3;
|
|
658
658
|
const indexRouteValue = 2;
|
|
659
659
|
const emptySegmentValue = 1;
|
|
@@ -740,7 +740,7 @@ function generatePath(originalPath, params) {
|
|
|
740
740
|
// Apply the splat
|
|
741
741
|
return stringify(params[star]);
|
|
742
742
|
}
|
|
743
|
-
const keyMatch = segment.match(/^:(\w+)(\??)$/);
|
|
743
|
+
const keyMatch = segment.match(/^:([\w-]+)(\??)$/);
|
|
744
744
|
if (keyMatch) {
|
|
745
745
|
const [, key, optional] = keyMatch;
|
|
746
746
|
let param = params[key];
|
|
@@ -789,7 +789,7 @@ function matchPath(pattern, pathname) {
|
|
|
789
789
|
if (isOptional && !value) {
|
|
790
790
|
memo[paramName] = undefined;
|
|
791
791
|
} else {
|
|
792
|
-
memo[paramName] =
|
|
792
|
+
memo[paramName] = (value || "").replace(/%2F/g, "/");
|
|
793
793
|
}
|
|
794
794
|
return memo;
|
|
795
795
|
}, {});
|
|
@@ -812,7 +812,7 @@ function compilePath(path, caseSensitive, end) {
|
|
|
812
812
|
let regexpSource = "^" + path.replace(/\/*\*?$/, "") // Ignore trailing / and /*, we'll handle it below
|
|
813
813
|
.replace(/^\/*/, "/") // Make sure it has a leading /
|
|
814
814
|
.replace(/[\\.*+^${}|()[\]]/g, "\\$&") // Escape special regex chars
|
|
815
|
-
.replace(/\/:(\w+)(\?)?/g, (_, paramName, isOptional) => {
|
|
815
|
+
.replace(/\/:([\w-]+)(\?)?/g, (_, paramName, isOptional) => {
|
|
816
816
|
params.push({
|
|
817
817
|
paramName,
|
|
818
818
|
isOptional: isOptional != null
|
|
@@ -841,22 +841,14 @@ function compilePath(path, caseSensitive, end) {
|
|
|
841
841
|
let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i");
|
|
842
842
|
return [matcher, params];
|
|
843
843
|
}
|
|
844
|
-
function
|
|
844
|
+
function decodePath(value) {
|
|
845
845
|
try {
|
|
846
|
-
return
|
|
846
|
+
return value.split("/").map(v => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
|
|
847
847
|
} catch (error) {
|
|
848
848
|
warning(false, "The URL path \"" + value + "\" could not be decoded because it is is a " + "malformed URL segment. This is probably due to a bad percent " + ("encoding (" + error + ")."));
|
|
849
849
|
return value;
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
|
-
function safelyDecodeURIComponent(value, paramName) {
|
|
853
|
-
try {
|
|
854
|
-
return decodeURIComponent(value);
|
|
855
|
-
} catch (error) {
|
|
856
|
-
warning(false, "The value for the URL param \"" + paramName + "\" will not be decoded because" + (" the string \"" + value + "\" is a malformed URL segment. This is probably") + (" due to a bad percent encoding (" + error + ")."));
|
|
857
|
-
return value;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
852
|
/**
|
|
861
853
|
* @private
|
|
862
854
|
*/
|
|
@@ -3707,7 +3699,11 @@ async function callLoaderOrAction(type, request, match, matches, manifest, mapRo
|
|
|
3707
3699
|
// Check between word boundaries instead of startsWith() due to the last
|
|
3708
3700
|
// paragraph of https://httpwg.org/specs/rfc9110.html#field.content-type
|
|
3709
3701
|
if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
|
3710
|
-
|
|
3702
|
+
if (result.body == null) {
|
|
3703
|
+
data = null;
|
|
3704
|
+
} else {
|
|
3705
|
+
data = await result.json();
|
|
3706
|
+
}
|
|
3711
3707
|
} else {
|
|
3712
3708
|
data = await result.text();
|
|
3713
3709
|
}
|