mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
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:
@@ -50,7 +50,7 @@ const layoutProps = {
|
|||||||
<div class="mx-auto flex w-full max-w-3xl justify-start px-2">
|
<div class="mx-auto flex w-full max-w-3xl justify-start px-2">
|
||||||
<button
|
<button
|
||||||
class="focus-outline mb-2 mt-8 flex hover:opacity-75"
|
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"
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
><path
|
><path
|
||||||
@@ -111,7 +111,7 @@ const layoutProps = {
|
|||||||
function addHeadingLinks() {
|
function addHeadingLinks() {
|
||||||
let headings = Array.from(document.querySelectorAll("h2, h3, h4, h5, h6"));
|
let headings = Array.from(document.querySelectorAll("h2, h3, h4, h5, h6"));
|
||||||
for (let heading of headings) {
|
for (let heading of headings) {
|
||||||
heading.classList.add("group")
|
heading.classList.add("group");
|
||||||
let link = document.createElement("a");
|
let link = document.createElement("a");
|
||||||
link.innerText = "#";
|
link.innerText = "#";
|
||||||
link.className = "heading-link hidden group-hover:inline-block ml-2";
|
link.className = "heading-link hidden group-hover:inline-block ml-2";
|
||||||
|
|||||||
Reference in New Issue
Block a user