Created
February 28, 2025 00:44
-
-
Save akku1139/6527ec5333c98df477fdf3aeedf3fbb3 to your computer and use it in GitHub Desktop.
aタグをクリックしたときにリロードせずページ遷移できる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("click", (e) => { | |
if(e.target.tagName === "A" && new URL(e.target.href).origin === location.origin) { | |
fetch(e.target.href).then((r) => | |
r.text().then((t) => { | |
history.pushState(null, null, e.target.href); | |
document.documentElement.innerHTML = t; | |
}) | |
); | |
e.preventDefault(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://discord.com/channels/1104402025988489299/1114234913777000558/1239570792501477376