Skip to content

Commit 9a696a8

Browse files
Fix URL Rewrite
1 parent 63d2c37 commit 9a696a8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/components/ConvertkitForm.astro

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@ const form = document.querySelector(".formkit-sticky-bar")
44
const fromNewsletter = queryParams.get("fromNewsletter")
55

66
if (fromNewsletter === "true") {
7+
queryParams.delete("fromNewsletter")
8+
const stringifiedParams = queryParams.toString()
79
history.replaceState(
810
null,
911
null,
10-
`${location.pathname}?${queryParams.toString()}${location.hash}`
12+
`${location.pathname}${stringifiedParams ? `?${queryParams.toString()}` : ""
13+
}${location.hash}`
1114
)
1215
localStorage.setItem("subscribed-to-newsletter", true)
1316
}
1417

1518
if (fromNewsletter === "false") {
19+
queryParams.delete("fromNewsletter")
20+
const stringifiedParams = queryParams.toString()
1621
history.replaceState(
1722
null,
1823
null,
19-
`${location.pathname}?${queryParams.toString()}${location.hash}`
24+
`${location.pathname}${stringifiedParams ? `?${queryParams.toString()}` : ""
25+
}${location.hash}`
2026
)
2127
localStorage.removeItem("subscribed-to-newsletter")
2228
localStorage.removeItem("date-of-last-newsletter-link")
@@ -87,5 +93,5 @@ document.addEventListener("click", e => {
8793
if (e.target.matches("[data-formkit-close]")) {
8894
sessionStorage.setItem("form-closed", true)
8995
}
90-
})
96+
})
9197
</script>

src/components/PageAnalytics.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ plausible("pageview", {
1919
})
2020

2121
if (shouldClean) {
22+
const stringifiedParams = queryParams.toString()
2223
history.replaceState(
2324
null,
2425
null,
25-
`${location.pathname}?${queryParams}${location.hash}`
26+
`${location.pathname}${stringifiedParams ? `?${queryParams.toString()}` : ""
27+
}${location.hash}`
2628
)
2729
}
2830
},

0 commit comments

Comments
 (0)