fix: update back button to redirect to home when no route history (#241)

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.
This commit is contained in:
Sat Naing
2024-01-22 11:03:41 +06:30
committed by GitHub
parent 629dbfda5b
commit 8f75f0a5e7
+2 -2
View File
@@ -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
@@ -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";