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:
@@ -29,8 +29,6 @@ const months = [
|
||||
"November",
|
||||
"December",
|
||||
];
|
||||
|
||||
const backUrl = SITE.showBackButton ? `?from=${Astro.url.pathname}` : "/";
|
||||
---
|
||||
|
||||
<Layout title={`Archives | ${SITE.title}`}>
|
||||
@@ -72,10 +70,7 @@ const backUrl = SITE.showBackButton ? `?from=${Astro.url.pathname}` : "/";
|
||||
)
|
||||
)
|
||||
.map(({ data, id }) => (
|
||||
<Card
|
||||
href={`/posts/${id}${backUrl}`}
|
||||
frontmatter={data}
|
||||
/>
|
||||
<Card href={`/posts/${id}`} frontmatter={data} />
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
@@ -84,6 +79,5 @@ const backUrl = SITE.showBackButton ? `?from=${Astro.url.pathname}` : "/";
|
||||
))
|
||||
}
|
||||
</Main>
|
||||
|
||||
<Footer />
|
||||
</Layout>
|
||||
|
||||
+11
-1
@@ -22,7 +22,7 @@ const recentPosts = sortedPosts.filter(({ data }) => !data.featured);
|
||||
|
||||
<Layout>
|
||||
<Header />
|
||||
<main id="main-content">
|
||||
<main id="main-content" data-layout="index">
|
||||
<section id="hero" class="pt-8 pb-6">
|
||||
<h1 class="my-4 inline-block text-4xl font-bold sm:my-8 sm:text-5xl">
|
||||
Mingalaba
|
||||
@@ -119,3 +119,13 @@ const recentPosts = sortedPosts.filter(({ data }) => !data.featured);
|
||||
</main>
|
||||
<Footer />
|
||||
</Layout>
|
||||
|
||||
<script>
|
||||
document.addEventListener("astro:page-load", () => {
|
||||
const indexLayout = (document.querySelector("#main-content") as HTMLElement)
|
||||
?.dataset?.layout;
|
||||
if (indexLayout) {
|
||||
sessionStorage.setItem("backUrl", "/");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user