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

234
Vistas
React - Cannot read properties of undefined (reading 'pathname')

I don't understand why the error appears. My task is to make animation between Routes. Can you suggest where I made a mistake? enter image description here I use react-spring package, i reinstalled it but nothing helped

 import React from 'react';
    import { Routes, Route, useLocation } from 'react-router-dom';
    import { useTransition, animated } from 'react-spring'
    
    import Home from './Home/Home';
    import Signup from './Form/Signup';
    import Login from './Form/Login';
    import Reset from './Form/Reset';
    import Shop from './Shop/Shop';
    import Dash from './../pages/Dashboard/Dashboard';
    
    const Main = () => {
    
      const location = useLocation();
      const transitions = useTransition(location, location => location.pathname, {
        from: { opacity: 0, transform: 'translate3d(100vw, 0, 0)' },
        enter: { opacity: 1, transform: 'translate3d(0, 0, 0)' },
        leave: { opacity: 0, transform: 'translate3d(-20vw, 0, 0)' },
      });
    
      return transitions.map(({ item: location, props, key }) =>  (
        <>
        <animated.div key={key} style={props}>
        <Routes location={location}>
          <Route path='/' element={<Home/>} />
          <Route exact path='/signup' element={<Signup/>}/>
          <Route exact path='/login' element={<Login/>}/>
          <Route exact path='/dashboard' element={<Dash/>}/>
          <Route exact path='/reset-password' element={<Reset/>}/>
          <Route exact path='/shop' element={<Shop/>}/>
        </Routes>
        </animated.div>
        </>
    
      ));
    };
    
    export default Main;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I actually think this is because you might be using v9 or react-spring yet the syntax you're writing in is v8.

Does this solve your issue?

    import React from 'react';
    import { Routes, Route, useLocation } from 'react-router-dom';
    import { useTransition, animated } from 'react-spring'
    
    import Home from './Home/Home';
    import Signup from './Form/Signup';
    import Login from './Form/Login';
    import Reset from './Form/Reset';
    import Shop from './Shop/Shop';
    import Dash from './../pages/Dashboard/Dashboard';
    
    const Main = () => {
    
      const location = useLocation();
      const transitions = useTransition(location, {
        key: location => location.pathname,
        from: { opacity: 0, transform: 'translate3d(100vw, 0, 0)' },
        enter: { opacity: 1, transform: 'translate3d(0, 0, 0)' },
        leave: { opacity: 0, transform: 'translate3d(-20vw, 0, 0)' },
      });
    
      return transitions.map((props, location) =>  (
        <>
        <animated.div style={props}>
        <Routes location={location}>
          <Route path='/' element={<Home/>} />
          <Route exact path='/signup' element={<Signup/>}/>
          <Route exact path='/login' element={<Login/>}/>
          <Route exact path='/dashboard' element={<Dash/>}/>
          <Route exact path='/reset-password' element={<Reset/>}/>
          <Route exact path='/shop' element={<Shop/>}/>
        </Routes>
        </animated.div>
        </>
    
      ));
    };
    
    export default Main;
about 4 years ago · Juan Pablo Isaza Denunciar
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