Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
Scroll restoration with Framer Motion on page transition in React Router 6

I want to make smooth page transition with scroll restoration. I have been trying to do scroll restoration with page transitions in React but can't make it smooth.

<Navbar />
  <AnimatePresence exitBeforeEnter>
    <ScrollToTop/>
    <Routes location={location} key={location.pathname}>
        <Route path="/" element={<Home />}/>
        <Route path="/about" element={<About />}/>
    </Routes>
  </AnimatePresence>
<Footer />

In the above code, I tried to put ScrollToTop inside AnimatePresence to make restore scroll while page is transitioning. However, I shows a warning saying that I have multiple children inside AnimatePresence, and page transition behaves strangely, as my Footer and Navbar kinda flashes on the page while it transitions. If I put ScrollToTop outside of the AnimatePresence, it first scrolls to top, and only then starts animation, which looks undesired.

My ScrollToTop.js file, which was suggested by react-router:

import { useEffect } from "react";
import { useLocation } from "react-router-dom";

export default function ScrollToTop() {
  const { pathname } = useLocation();

  useEffect(() => {
    window.scrollTo(0, 0);
  }, [pathname]);

  return null;
}

Versions: "framer-motion": "^6.2.4" and "react-router-dom": "^6.2.1".

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda