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

168
Views
Framer-motion not working when I use the useLocation hook

I am trying to use the framer motion library to create animations between page transitions. Everything seems to be working and I am able to create transitions that both fade in and out and also sweep in through the y-axis until I use the useLocation hook, then all of my components disappear and I am only left with my background screen. Since I am able to create the animations without the useLocation hook I am wondering if maybe I am using it wrong

import { BrowserRouter as Router, Routes, Route, useLocation } from 'react-router-dom'
import './App.css';
import Navbar from "./components/Navbar.js"
import Home from "./pages/Home.js"
import About from "./pages/About"

import Projects from "./pages/Projects"
import Contact from "./pages/Contact"
import { Container, CssBaseline } from '@mui/material';
import { ThemeProvider, createTheme } from "@mui/material/styles";
import { AnimatePresence } from 'framer-motion';


export const primaryColor = "#161616";




const theme = createTheme({

  palette: {
    primary: {
      main: primaryColor
    },


  },


});

const pageTransitions = {
  in: {
    opacity: 1,
    y: 0

  },
  out: {
    opacity: 0,
    y: '-100vh'

  }
};

function App() {

  const location = useLocation();
  return (
    <>
      <ThemeProvider theme={theme}>
        <CssBaseline />

        <Router>
          <Navbar />
          <Container maxWidth="md">
            <AnimatePresence exitBeforeEnter initial={false}>
              <Routes location={location} key={location.pathname} >

                <Route path='/' element={<Home pageTransitions={pageTransitions} />} />
                <Route path='/about' element={<About pageTransitions={pageTransitions} />} />
                <Route path='/projects' element={<Projects pageTransitions={pageTransitions} />} />
                <Route path='/contact' element={<Contact pageTransitions={pageTransitions} />} />

              </Routes>
            </AnimatePresence>


          </Container>



        </Router>

      </ThemeProvider>
    </>
  );
}

export default App;
about 4 years ago · Juan Pablo Isaza
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!