@remix-run/router 0.0.0-experimental-e192105b → 0.0.0-experimental-178bc9ee
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 +28 -0
- package/dist/index.d.ts +2 -2
- package/dist/router.cjs.js +118 -89
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +9 -1
- package/dist/router.js +115 -88
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +118 -89
- 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 +2 -1
- package/index.ts +2 -1
- package/package.json +1 -1
- package/router.ts +147 -77
- package/utils.ts +35 -5
package/utils.ts
CHANGED
|
@@ -349,7 +349,7 @@ type _PathParam<Path extends string> =
|
|
|
349
349
|
* "/:a/:b" -> "a" | "b"
|
|
350
350
|
* "/:a/b/:c/*" -> "a" | "c" | "*"
|
|
351
351
|
*/
|
|
352
|
-
type PathParam<Path extends string> =
|
|
352
|
+
export type PathParam<Path extends string> =
|
|
353
353
|
// check if path is just a wildcard
|
|
354
354
|
Path extends "*" | "/*"
|
|
355
355
|
? "*"
|
|
@@ -1145,6 +1145,17 @@ export function getPathContributingMatches<
|
|
|
1145
1145
|
);
|
|
1146
1146
|
}
|
|
1147
1147
|
|
|
1148
|
+
// Return the array of pathnames for the current route matches - used to
|
|
1149
|
+
// generate the routePathnames input for resolveTo()
|
|
1150
|
+
export function getResolveToMatches<
|
|
1151
|
+
T extends AgnosticRouteMatch = AgnosticRouteMatch
|
|
1152
|
+
>(matches: T[]) {
|
|
1153
|
+
// Use the full pathname for the leaf match so we include splat values for "." links
|
|
1154
|
+
return getPathContributingMatches(matches).map((match, idx) =>
|
|
1155
|
+
idx === matches.length - 1 ? match.pathname : match.pathnameBase
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1148
1159
|
/**
|
|
1149
1160
|
* @private
|
|
1150
1161
|
*/
|
|
@@ -1188,17 +1199,36 @@ export function resolveTo(
|
|
|
1188
1199
|
// `to` values that do not provide a pathname. `to` can simply be a search or
|
|
1189
1200
|
// hash string, in which case we should assume that the navigation is relative
|
|
1190
1201
|
// to the current location's pathname and *not* the route pathname.
|
|
1191
|
-
if (
|
|
1202
|
+
if (toPathname == null) {
|
|
1192
1203
|
from = locationPathname;
|
|
1204
|
+
} else if (isPathRelative) {
|
|
1205
|
+
let fromSegments = routePathnames[routePathnames.length - 1]
|
|
1206
|
+
.replace(/^\//, "")
|
|
1207
|
+
.split("/");
|
|
1208
|
+
|
|
1209
|
+
if (toPathname.startsWith("..")) {
|
|
1210
|
+
let toSegments = toPathname.split("/");
|
|
1211
|
+
|
|
1212
|
+
// With relative="path", each leading .. segment means "go up one URL segment"
|
|
1213
|
+
while (toSegments[0] === "..") {
|
|
1214
|
+
toSegments.shift();
|
|
1215
|
+
fromSegments.pop();
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
to.pathname = toSegments.join("/");
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
from = "/" + fromSegments.join("/");
|
|
1193
1222
|
} else {
|
|
1194
1223
|
let routePathnameIndex = routePathnames.length - 1;
|
|
1195
1224
|
|
|
1196
1225
|
if (toPathname.startsWith("..")) {
|
|
1197
1226
|
let toSegments = toPathname.split("/");
|
|
1198
1227
|
|
|
1199
|
-
//
|
|
1200
|
-
// URL segment". This is a key
|
|
1201
|
-
//
|
|
1228
|
+
// With relative="route" (the default), each leading .. segment means
|
|
1229
|
+
// "go up one route" instead of "go up one URL segment". This is a key
|
|
1230
|
+
// difference from how <a href> works and a major reason we call this a
|
|
1231
|
+
// "to" value instead of a "href".
|
|
1202
1232
|
while (toSegments[0] === "..") {
|
|
1203
1233
|
toSegments.shift();
|
|
1204
1234
|
routePathnameIndex -= 1;
|