Skip to content

Commit

Permalink
Merge branch 'dev' into brophdawg11/submitting-fetcher-persist-revali…
Browse files Browse the repository at this point in the history
…dation
  • Loading branch information
brophdawg11 committed Dec 7, 2023
2 parents 34abd40 + a76ee41 commit 8c508d8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-ligers-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

De-dup relative path logic in `resolveTo`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
},
"filesize": {
"packages/router/dist/router.umd.min.js": {
"none": "50.2 kB"
"none": "50.0 kB"
},
"packages/react-router/dist/react-router.production.min.js": {
"none": "14.6 kB"
Expand Down
33 changes: 5 additions & 28 deletions packages/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,37 +1209,16 @@ export function resolveTo(
// to the current location's pathname and *not* the route pathname.
if (toPathname == null) {
from = locationPathname;
} else if (isPathRelative) {
let fromSegments =
routePathnames.length === 0
? []
: routePathnames[routePathnames.length - 1]
.replace(/^\//, "")
.split("/");

if (toPathname.startsWith("..")) {
let toSegments = toPathname.split("/");

// With relative="path", each leading .. segment means "go up one URL segment"
while (toSegments[0] === "..") {
toSegments.shift();
fromSegments.pop();
}

to.pathname = toSegments.join("/");
}

from = "/" + fromSegments.join("/");
} else {
let routePathnameIndex = routePathnames.length - 1;

if (toPathname.startsWith("..")) {
// With relative="route" (the default), each leading .. segment means
// "go up one route" instead of "go up one URL segment". This is a key
// difference from how <a href> works and a major reason we call this a
// "to" value instead of a "href".
if (!isPathRelative && toPathname.startsWith("..")) {
let toSegments = toPathname.split("/");

// With relative="route" (the default), each leading .. segment means
// "go up one route" instead of "go up one URL segment". This is a key
// difference from how <a href> works and a major reason we call this a
// "to" value instead of a "href".
while (toSegments[0] === "..") {
toSegments.shift();
routePathnameIndex -= 1;
Expand All @@ -1248,8 +1227,6 @@ export function resolveTo(
to.pathname = toSegments.join("/");
}

// If there are more ".." segments than parent routes, resolve relative to
// the root / URL.
from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
}

Expand Down

0 comments on commit 8c508d8

Please sign in to comment.