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

598
Visualizações
In Next.js is there a way to determine if if scrollRestoration was used, or even if the back button was used?

I am using the scrollRestoration feature of Next.js to restore the page position when a back button is pressed. The problem, is that it doesn't restore the horizontal scroll position of the carousels on that page. So I have created my own session variables to track the position of each carousel and restore them on page load. The problem, is that I ONLY want to restore these scroll positions if the back/forward button was pressed. If there is an indicator that scrollRestoration was used on the page I could use that, otherwise, if there is an indication that the page was visited using the forward/back buttons that would also solve it.

Any ideas?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Never done this but my instinct would be:

  • Make a wrapper component, expose the next/router in your component
  • Set up an useEffect that updates on router.pathName changes
  • Set up a condition in the effect that watches History.back()

That kind of goes around the framework, but it doesn't look like Next exposes what you're looking for.

about 4 years ago · Juan Pablo Isaza Relatório

0

i have figured out how to determine if scrollRestoration is set for a page.

React.useEffect(() => {
    const hasScrollHistory = sessionStorage.getItem(`__next_scroll_${window.history.state.idx}`);
    if (hasScrollHistory) {
        // do your restore logic here
    }
}, []);
about 4 years ago · Juan Pablo Isaza Relatório
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