Skip to content

Issues with Hash Routing #83

@dairyisscary

Description

@dairyisscary

I have a page with a table of contents, HTML looks something like this:

<article>
  <h1 id="one">...</h1>
  <h2 id="two">...</h2>
  <h2 id="three">...</h2>
</article>

Table of Contents
<ol>
  <li><a href="#one">one</a></li>
  <li><a href="#two">two</a></li>
  <li><a href="#three">three</a></li>
</ol>

I'm rendering the HTML with template like this, though i did try plain <a> tags

<For each={tableOfContents()}>
  {({ id, text }) => (
    <li>
      <Link href={`#${id}`}>{text}</Link>
    </li>
  )}
</For>

theses are hash links to items on the same page/route. they appear to make the page scroll to the top, rather than to the item within the page. I'm not entirely sure what the issue is but I did fix the issue by tricking the anchor click method. i added taget="_self" to the anchor so the click handler early returns and browser default behavior takes over.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions