Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

397
Visualizações
Anchor links not working in Next.JS that are dynamically generated

I wrote an algorithm to parse and generate table of contents based on my markdown files. The table of contents output from markdown is raw HTML strings that I set using setDangerouslyInnerHTML.

  • Table of Contents library I made here

Snippet

const TableOfContents = ({ toc }) => {
  return (
    <div className={post["toc"]}>
      <h2>Table of Contents</h2>
      <div dangerouslySetInnerHTML={{ __html: toc }}></div>
    </div>
  );
};

The problem is, the standard href links on the li elements are not triggering anchor tag movements on the page.

The headers on the page have an id like <h1 id="test>.. and the corresponding

<li><a href="#test">test</a></li> doesn't trigger the navigation. Looking online, I know <Link> is recommended, but my generation is dynamic and all I do is interpolate the string into the page, so I haven't figured out a way to have any fancy JSX or function invocation embedded into the string. However, I'm still confused why the standard HTML clicking would not work?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda