Closed GVodyanov closed 6 months ago
Should there be no way to use native anchor jumps in hash mode? In my case, I added click events to the elements in the TOC to enable anchor jumps: Note that you should execute the code after the TOC generation.
\\ other code
const titleElments = document.querySelectorAll(".reference-link"); // select the title elements in content
\\ other code
let tocContainer = document.querySelector(".markdown-toc-list"); // select your toc cantainer
let liElements = tocContainer.getElementsByTagName("li");
for (let i = 0; i < liElements.length; i++) {
let el = liElements[i].firstChild;
el.addEventListener("click", function (event) {
event.preventDefault();
titleElments[i].scrollIntoView({
behavior: "smooth",
});
});
observer.observe(titleElments[i]);
}
When using with vue-router hash routing, this link:
http://localhost:5173/#/note/5
becomes thishttp://localhost:5173/#/addizione-e-sottrazione
when clicking on a toc heading, causing the page to be empty.
We won't support this because one of our goal is to be semantically correct. Using # to set a history landmark is something we used before History API existed. Therefore, modern sites and apps SHOULD (in RFC 2119 terms) use it instead and keep the hash fragment to SEO.
When using with vue-router hash routing, this link:
http://localhost:5173/#/note/5
becomes thishttp://localhost:5173/#/addizione-e-sottrazione
when clicking on a toc heading, causing the page to be empty.