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

246
Visualizações
barba.js Page reloading when pressing back button

I have a transition from one page to another using barba.js, after visiting that next page if you hit the back button it doesn't go back to the first page. The URL quickly updates to the first, then back the second URL and then it just refreshes the second page.

After one (or more) clicks of the back button, it returns to the first page.

    const mainOverlay = document.querySelector("#main-overlay");
    if (history.scrollRestoration) {
      history.scrollRestoration = "manual";
    }

    barba.init({
      transitions: [
        {
          name: "home",
          leave(data) {
            // Move target element
            const target = data.trigger.closest(".transition-target");
            if (target) {
              const yDistance = target.getBoundingClientRect().top;
              var tl = gsap.timeline();

              tl.to(target, {
                top: -(yDistance - 31) + "px",
                left: "0",
                width: "100%",
                zIndex: 100,
                duration: 0.9,
                ease: "expo.out",
              });
              return tl.play();
            }
          },
          enter(data) {
            window.scrollTo(0, 0);
            const newTarget =
              data.next.container.querySelector(".transition-target");
            var tl = gsap.timeline();


            tl.to(window, { scrollTo: { y: 0 }, duration: 0 })
              .to(newTarget, {
                zIndex: 5,
                duration: 0,
              });
          },
        },
      ],
    });

The expected behaviour is on clicking the back button it just returns to the first page. No transition is expected during that.

HTML if needed:

    <body>
        <div data-barba="wrapper">
            <div class="relative" data-barba="container" data-barba-namespace="home">
                <div id="main-overlay" class="fixed w-full h-full z-40 bg-white hidden opacity-0"></div>
                ...
            </div>
    
        </div>
     </body>
about 4 years ago · Santiago Gelvez
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