'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;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
