Skip to content

Commit

Permalink
fix: fix go back button (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
csosamorales authored Jun 10, 2024
1 parent 93dd6f0 commit d66074c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export async function getStaticPaths() {
}));
}
const back = () => {};
const { entry } = Astro.props;
const { Content } = await entry.render();
const { collection, id, slug } = entry;
Expand All @@ -33,7 +31,7 @@ const githubEditUrlPathname = generateGitHubEditLink({
slug={slug}
>
<article class="blog">
<div class="mb-10 w-fit" onclick="history.back()">
<div class="mb-10 w-fit" id="goBackButton">
<ButtonGray className="flex items-center justify-center gap-12 px-5">
<div>Go Back</div>
</ButtonGray>
Expand All @@ -50,3 +48,13 @@ const githubEditUrlPathname = generateGitHubEditLink({
<GithubEditLink pathname={githubEditUrlPathname} />
</article>
</BlogPageLayout>

<script>
document.getElementById('goBackButton')?.addEventListener('click', () => {
if (history.length > 2) {
history.back();
} else {
window.location.href = '/blog';
}
});
</script>

0 comments on commit d66074c

Please sign in to comment.