Skip to content

Commit 8e9d8ef

Browse files
committed
href types normalize route full path
1 parent 263c979 commit 8e9d8ef

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

integration/typegen-test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ test.describe("typegen", () => {
401401
route("no-params", "routes/no-params.tsx"),
402402
route("required-param/:req", "routes/required-param.tsx"),
403403
route("optional-param/:opt?", "routes/optional-param.tsx"),
404+
route("/leading-and-trailing-slash/", "routes/leading-and-trailing-slash.tsx"),
404405
route("some-other-route", "routes/some-other-route.tsx"),
405406
] satisfies RouteConfig;
406407
`,
@@ -413,6 +414,9 @@ test.describe("typegen", () => {
413414
"app/routes/optional-param.tsx": tsx`
414415
export default function Component() {}
415416
`,
417+
"app/routes/leading-and-trailing-slash.tsx": tsx`
418+
export default function Component() {}
419+
`,
416420
"app/routes/some-other-route.tsx": tsx`
417421
import { href } from "react-router"
418422
@@ -428,6 +432,10 @@ test.describe("typegen", () => {
428432
href("/optional-param/:opt?")
429433
href("/optional-param/:opt?", { opt: "hello" })
430434
435+
href("/leading-and-trailing-slash")
436+
// @ts-expect-error
437+
href("/leading-and-trailing-slash/")
438+
431439
export default function Component() {}
432440
`,
433441
});

packages/react-router-dev/typegen/route.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ export function lineage(
1616

1717
export function fullpath(lineage: RouteManifestEntry[]) {
1818
if (lineage.length === 1 && lineage[0].id === "root") return "/";
19-
return lineage
20-
.map((route) => route.path)
21-
.filter((path) => path !== undefined)
22-
.join("/");
19+
return (
20+
"/" +
21+
lineage
22+
.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, ""))
23+
.filter((path) => path !== undefined && path !== "")
24+
.join("/")
25+
);
2326
}

0 commit comments

Comments
 (0)