Skip to content

Commit 6f791cf

Browse files
committed
Add rewrite.
1 parent f6feda7 commit 6f791cf

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/pages/[code].astro

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
---
22
import { getCollection } from "astro:content";
3-
43
export async function getStaticPaths() {
54
const sessions = await getCollection("sessions");
65
return sessions.map((entry) => ({
76
params: { code: entry.data.code },
87
props: { slug: entry.id},
98
}));
109
}
11-
1210
const { slug } = Astro.props;
1311
return Astro.rewrite(`/session/${slug}`);
1412
---

src/pages/session/[slug].astro

Lines changed: 14 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,16 @@ const nextSessionsOrdered = sameRoomNextSession
233233
</footer>
234234
</Section>
235235
</Layout>
236+
237+
<script is:inline define:vars={{ slug }}>
238+
// Check if the current URL contains the entry ID
239+
const currentUrl = window.location.pathname;
240+
const expectedUrl = `/session/${slug}`;
241+
242+
// If the URL doesn't match the expected URL with the entry ID, replace it
243+
if (currentUrl !== expectedUrl) {
244+
// Use history.replaceState to update the URL without refreshing the page
245+
window.history.replaceState({}, '', expectedUrl);
246+
console.log(`URL updated to match entry ID: ${expectedUrl}`);
247+
}
248+
</script>

0 commit comments

Comments
 (0)