Skip to content

Commit 75cfeac

Browse files
author
baudbot-agent
committed
fix: share button generates correct deep link URLs
The createDeepLink function was missing the base route prefix (package-managers, task-runners, registries), producing broken URLs like /#/average/per-package-install-time-by-fixture/next instead of /#/package-managers/average/per-package-install-time-by-fixture/next. Now uses useLocation to extract the current base route and prepend it to the generated deep link path. Also removed unused filters parameter from createDeepLink.
1 parent 47a6ee1 commit 75cfeac

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

‎app/src/components/share-button.tsx‎

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState } from "react";
2+
import { useLocation } from "react-router";
23
import { Button } from "@/components/ui/button";
34
import { Share } from "@/components/icons";
45
import { Check } from "lucide-react";
@@ -17,36 +18,19 @@ import type { VariantProps } from "class-variance-authority";
1718
import type { ComponentProps } from "react";
1819

1920
const createDeepLink = (
21+
baseRoute: string,
2022
variation: string,
2123
section?: string,
2224
fixture?: string,
23-
filters?: {
24-
packageManagers?: string[];
25-
fixtures?: string[];
26-
},
2725
): string => {
28-
let path = `/${variation}`;
26+
let path = `/${baseRoute}/${variation}`;
2927
if (section) {
3028
path += `/${section}`;
3129
}
3230
if (fixture) {
3331
path += `/${fixture}`;
3432
}
3533

36-
if (filters && (filters.packageManagers || filters.fixtures)) {
37-
const params = new URLSearchParams();
38-
39-
if (filters.packageManagers && filters.packageManagers.length > 0) {
40-
params.set("tools", filters.packageManagers.join(","));
41-
}
42-
43-
if (filters.fixtures && filters.fixtures.length > 0) {
44-
params.set("fixtures", filters.fixtures.join(","));
45-
}
46-
47-
path += `?${params.toString()}`;
48-
}
49-
5034
return path;
5135
};
5236

@@ -67,10 +51,13 @@ export const ShareButton = ({
6751
className,
6852
}: ShareButtonProps) => {
6953
const [copied, setCopied] = useState<boolean>(false);
54+
const location = useLocation();
7055
const Icon = copied ? Check : Share;
7156

7257
const handleShare = async () => {
73-
const deepLink = createDeepLink(variation, section, fixture);
58+
// Extract the base route (package-managers, task-runners, registries) from the current path
59+
const baseRoute = location.pathname.split("/")[1] || "package-managers";
60+
const deepLink = createDeepLink(baseRoute, variation, section, fixture);
7461
const url = `${window.location.origin}${window.location.pathname}#${deepLink}`;
7562

7663
try {

0 commit comments

Comments
 (0)