mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
feat: update back button logic
Instead of saving back url in the param, save the back url info inside session.
This commit is contained in:
@@ -19,15 +19,19 @@ import { SITE } from "@/config";
|
||||
)
|
||||
}
|
||||
|
||||
<script is:inline data-astro-rerun>
|
||||
<script>
|
||||
/* Update Search Praam */
|
||||
function updateGoBackUrl() {
|
||||
const backButton = document.querySelector("#back-button");
|
||||
const params = new URL(document.location.toString()).searchParams;
|
||||
const backButton: HTMLAnchorElement | null =
|
||||
document.querySelector("#back-button");
|
||||
|
||||
if (params.has("from")) {
|
||||
backButton.href = params.get("from");
|
||||
const backUrl = sessionStorage.getItem("backUrl");
|
||||
|
||||
if (backUrl && backButton) {
|
||||
backButton.href = backUrl;
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("astro:page-load", updateGoBackUrl);
|
||||
updateGoBackUrl();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user