@remix-run/router 1.0.2 → 1.0.3-pre.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 +15 -2
- package/dist/index.d.ts +2 -2
- package/dist/router.cjs.js +317 -160
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +317 -161
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +3411 -0
- package/dist/router.umd.js.map +1 -0
- package/dist/router.umd.min.js +12 -0
- package/dist/router.umd.min.js.map +1 -0
- package/dist/utils.d.ts +24 -0
- package/history.ts +2 -2
- package/index.ts +5 -2
- package/package.json +2 -1
- package/router.ts +375 -158
- package/utils.ts +54 -1
package/utils.ts
CHANGED
|
@@ -329,7 +329,13 @@ export function matchRoutes<
|
|
|
329
329
|
|
|
330
330
|
let matches = null;
|
|
331
331
|
for (let i = 0; matches == null && i < branches.length; ++i) {
|
|
332
|
-
matches = matchRouteBranch<string, RouteObjectType>(
|
|
332
|
+
matches = matchRouteBranch<string, RouteObjectType>(
|
|
333
|
+
branches[i],
|
|
334
|
+
// incoming pathnames are always encoded from either window.location or
|
|
335
|
+
// from route.navigate, but we want to match against the unencoded paths
|
|
336
|
+
// in the route definitions
|
|
337
|
+
safelyDecodeURI(pathname)
|
|
338
|
+
);
|
|
333
339
|
}
|
|
334
340
|
|
|
335
341
|
return matches;
|
|
@@ -702,6 +708,21 @@ function compilePath(
|
|
|
702
708
|
return [matcher, paramNames];
|
|
703
709
|
}
|
|
704
710
|
|
|
711
|
+
function safelyDecodeURI(value: string) {
|
|
712
|
+
try {
|
|
713
|
+
return decodeURI(value);
|
|
714
|
+
} catch (error) {
|
|
715
|
+
warning(
|
|
716
|
+
false,
|
|
717
|
+
`The URL path "${value}" could not be decoded because it is is a ` +
|
|
718
|
+
`malformed URL segment. This is probably due to a bad percent ` +
|
|
719
|
+
`encoding (${error}).`
|
|
720
|
+
);
|
|
721
|
+
|
|
722
|
+
return value;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
705
726
|
function safelyDecodeURIComponent(value: string, paramName: string) {
|
|
706
727
|
try {
|
|
707
728
|
return decodeURIComponent(value);
|
|
@@ -835,6 +856,38 @@ function getInvalidPathError(
|
|
|
835
856
|
);
|
|
836
857
|
}
|
|
837
858
|
|
|
859
|
+
/**
|
|
860
|
+
* @private
|
|
861
|
+
*
|
|
862
|
+
* When processing relative navigation we want to ignore ancestor routes that
|
|
863
|
+
* do not contribute to the path, such that index/pathless layout routes don't
|
|
864
|
+
* interfere.
|
|
865
|
+
*
|
|
866
|
+
* For example, when moving a route element into an index route and/or a
|
|
867
|
+
* pathless layout route, relative link behavior contained within should stay
|
|
868
|
+
* the same. Both of the following examples should link back to the root:
|
|
869
|
+
*
|
|
870
|
+
* <Route path="/">
|
|
871
|
+
* <Route path="accounts" element={<Link to=".."}>
|
|
872
|
+
* </Route>
|
|
873
|
+
*
|
|
874
|
+
* <Route path="/">
|
|
875
|
+
* <Route path="accounts">
|
|
876
|
+
* <Route element={<AccountsLayout />}> // <-- Does not contribute
|
|
877
|
+
* <Route index element={<Link to=".."} /> // <-- Does not contribute
|
|
878
|
+
* </Route
|
|
879
|
+
* </Route>
|
|
880
|
+
* </Route>
|
|
881
|
+
*/
|
|
882
|
+
export function getPathContributingMatches<
|
|
883
|
+
T extends AgnosticRouteMatch = AgnosticRouteMatch
|
|
884
|
+
>(matches: T[]) {
|
|
885
|
+
return matches.filter(
|
|
886
|
+
(match, index) =>
|
|
887
|
+
index === 0 || (match.route.path && match.route.path.length > 0)
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
|
|
838
891
|
/**
|
|
839
892
|
* @private
|
|
840
893
|
*/
|