Skip to content

Commit

Permalink
fix: update back button to redirect to home when no route history (#241)
Browse files Browse the repository at this point in the history
Update back button in PostDetails.astro to redirect to home page when
there's no route history.
If a blog post url is pasted in the browser and there's no route history
,prior to this commit, back button did not work as expected.
Now, if there's somewhere to go back, the back button will go back to the
previous route.
If not, the back button will redirect to home page.
  • Loading branch information
satnaing authored Jan 22, 2024
1 parent 629dbfd commit 8f75f0a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/layouts/PostDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const layoutProps = {
<div class="mx-auto flex w-full max-w-3xl justify-start px-2">
<button
class="focus-outline mb-2 mt-8 flex hover:opacity-75"
onclick="history.back()"
onclick="(() => (history.length === 1) ? window.location = '/' : history.back())()"
>
<svg xmlns="http://www.w3.org/2000/svg"
><path
Expand Down Expand Up @@ -111,7 +111,7 @@ const layoutProps = {
function addHeadingLinks() {
let headings = Array.from(document.querySelectorAll("h2, h3, h4, h5, h6"));
for (let heading of headings) {
heading.classList.add("group")
heading.classList.add("group");
let link = document.createElement("a");
link.innerText = "#";
link.className = "heading-link hidden group-hover:inline-block ml-2";
Expand Down

0 comments on commit 8f75f0a

Please sign in to comment.