Skip to content

Commit 2aeec84

Browse files
committed
remove reload on hash links in about-site
1 parent 4de4446 commit 2aeec84

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/routes/about-site.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { createFileRoute } from "@tanstack/react-router";
1+
import { createFileRoute, ParsedLocation } from "@tanstack/react-router";
22
import { fetchMDXCode, fetchSingleMDXFrontMatter } from "~/utils/mdx-fetcher";
33
import { MDXPost } from "~/components/page";
44

5+
let prevLoc: ParsedLocation | null = null;
6+
57
export const Route = createFileRoute("/about-site")({
68
loader: async () => {
79
return {
@@ -14,6 +16,22 @@ export const Route = createFileRoute("/about-site")({
1416
};
1517
},
1618
component: AboutComponent,
19+
shouldReload(match) {
20+
try {
21+
if (match.cause === "enter" || match.cause === "preload") return true;
22+
23+
const hashOnly =
24+
prevLoc &&
25+
prevLoc.pathname === match.location.pathname &&
26+
prevLoc.searchStr === match.location.searchStr;
27+
28+
if (hashOnly) return false;
29+
30+
return true;
31+
} finally {
32+
prevLoc = match.location;
33+
}
34+
},
1735
});
1836

1937
function AboutComponent() {

0 commit comments

Comments
 (0)