Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!