Last active
May 28, 2022 10:01
-
-
Save mfrancois3k/a767b94aeb901be5ad96dfee8cb30e90 to your computer and use it in GitHub Desktop.
Framer motion AnimatedRoutes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reference | |
https://github.com/oyedeletemitope/page-transition-in-react-using-framer-motion/blob/master/src/App.js#L5 | |
import React from "react"; | |
import { Routes, Route, useLocation } from "react-router-dom"; | |
import Home from "./Home"; | |
import Contact from "./Contact"; | |
import About from "./About"; | |
import { AnimatePresence } from "framer-motion"; | |
function AnimatedRoutes() { | |
const location = useLocation(); | |
return ( | |
<AnimatePresence exitBeforeEnter> | |
<Routes key={location.pathname} location={location}> | |
<Route path="/" element={<Home />} /> | |
<Route path="/home" element={<Home />} /> | |
<Route path="/about" element={<About />} /> | |
<Route path="/contact" element={<Contact />} /> | |
</Routes> | |
</AnimatePresence> | |
); | |
} | |
export default AnimatedRoutes; | |
App.js | |
import { BrowserRouter as Router } from "react-router-dom"; | |
import Navbar from "./pages/Navbar"; | |
import AnimatedRoutes from "./pages/AnimatedRoutes"; | |
function App() { | |
return ( | |
<Router> | |
<Navbar /> | |
<AnimatedRoutes /> | |
</Router> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment