Skip to content

Commit 8fbb7ef

Browse files
committed
feat: give examples their own url
1 parent 6edd26c commit 8fbb7ef

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/client/App.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,7 @@ const ExampleSelector: FC = () => {
314314
<DropdownMenuPortal>
315315
<DropdownMenuContent>
316316
{Object.entries(examples).map(([ slug, title ]) => {
317-
const params = new URLSearchParams();
318-
params.append("example", slug);
319-
320-
const href = `${window.location.origin}/parameters?${params.toString()}`;
317+
const href = `${window.location.origin}/parameters/example/${slug}`;
321318
return (
322319
<DropdownMenuItem key={slug} asChild={true}>
323320
<a href={href} target="_blank" rel="noreferrer">

src/server/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ app.route("/api", api);
2121
app.use(trimTrailingSlash());
2222

2323
// Serves the main web application. This must come after the API route.
24-
app.get("/parameters/:shareId?", async (c) => {
24+
app.get("/parameters/:shareId?/:example?", async (c) => {
2525
const getExampleCode = async (): Promise<string | null> => {
26-
const { shareId } = c.req.param();
27-
const { example } = c.req.query();
26+
const { shareId, example } = c.req.param();
2827

29-
if (shareId) {
28+
if (shareId && shareId !== "example") {
3029
const shareData = await getShareData(shareId);
3130
return shareData?.code ?? null;
3231
}
@@ -35,7 +34,7 @@ app.get("/parameters/:shareId?", async (c) => {
3534
return null;
3635
}
3736

38-
return examples[example];
37+
return examples[example] ?? null;
3938
};
4039

4140
// Along with the vite React plugin this enables HMR within react while

0 commit comments

Comments
 (0)