Skip to content

Commit c2c948a

Browse files
authored
1 parent 686089a commit c2c948a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/pages/[code].astro

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
import { getCollection } from "astro:content";
3+
export async function getStaticPaths() {
4+
const sessions = await getCollection("sessions");
5+
return sessions.map((entry) => ({
6+
params: { code: entry.data.code },
7+
props: { slug: entry.id},
8+
}));
9+
}
10+
const { slug } = Astro.props;
11+
return Astro.rewrite(`/session/${slug}`);
12+
---

src/pages/session/[slug].astro

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function getStaticPaths() {
2121
const sessions = await getCollection("sessions");
2222
2323
const { entry } = Astro.props;
24-
24+
const slug = entry.id;
2525
const speakers = await getEntries(entry.data.speakers);
2626
2727
// Resolve session codes to session data
@@ -233,3 +233,12 @@ const nextSessionsOrdered = sameRoomNextSession
233233
</footer>
234234
</Section>
235235
</Layout>
236+
237+
<script is:inline define:vars={{ slug }}>
238+
const currentUrl = window.location.pathname;
239+
const expectedUrl = `/session/${slug}`;
240+
241+
if (currentUrl !== expectedUrl) {
242+
window.history.replaceState({}, '', expectedUrl);
243+
}
244+
</script>

0 commit comments

Comments
 (0)