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

223
Visualizações
Scroll to an Anchor Link on a React App Using a Link on an External Page

I have an external page with links that point back to my main react application using anchor tags. (ex: External page has a link to app/#platform).

I've been trying to find a way to make the page scroll to this anchor but have had no luck. The issue, I think, is that the anchors don't exist until the page renders.

When clicking links on the React App to the anchor tags -- everything works fine. The issue is in navigating from outside the React app.

I'm using React V18 and React Router V6.

My current best stab is in adding a useEffect that catches the hash and attempts to scroll. But it's not working either.

  useEffect(() => {

    const element = document.getElementById(location.hash);

    setTimeout(() => {
      window.scrollTo({
        behavior: element ? "smooth" : "auto",
        top: element ? element.offsetTop : 0
      });
     }, 100);
    }, [location]);
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