1+ import React from 'react' ;
2+ import { Routes , Route , useLocation } from 'react-router-dom' ;
3+ import { AnimatePresence , motion } from 'framer-motion' ;
4+ import HomePage from '../pages/HomePage' ;
5+ import BlogPage from '../pages/BlogPage' ;
6+ import BlogPostPage from '../pages/BlogPostPage' ;
7+ import ProjectsPage from '../pages/ProjectsPage' ;
8+ import ProjectPage from '../pages/ProjectPage' ;
9+ import AboutPage from '../pages/AboutPage' ;
10+ import NotFoundPage from '../pages/NotFoundPage' ;
11+
12+ const pageVariants = {
13+ initial : {
14+ opacity : 0
15+ } ,
16+ in : {
17+ opacity : 1
18+ } ,
19+ out : {
20+ opacity : 0
21+ }
22+ } ;
23+
24+ const pageTransition = {
25+ type : "tween" ,
26+ ease : "easeInOut" ,
27+ duration : 0.3
28+ } ;
29+
30+ function AnimatedRoutes ( ) {
31+ const location = useLocation ( ) ;
32+
33+ return (
34+ < AnimatePresence mode = "wait" >
35+ < Routes location = { location } key = { location . pathname } >
36+ < Route path = "/" element = { < motion . div initial = "initial" animate = "in" exit = "out" variants = { pageVariants } transition = { pageTransition } > < HomePage /> </ motion . div > } />
37+ < Route path = "/blog" element = { < motion . div initial = "initial" animate = "in" exit = "out" variants = { pageVariants } transition = { pageTransition } > < BlogPage /> </ motion . div > } />
38+ < Route path = "/blog/:slug" element = { < motion . div initial = "initial" animate = "in" exit = "out" variants = { pageVariants } transition = { pageTransition } > < BlogPostPage /> </ motion . div > } />
39+ < Route path = "/projects" element = { < motion . div initial = "initial" animate = "in" exit = "out" variants = { pageVariants } transition = { pageTransition } > < ProjectsPage /> </ motion . div > } />
40+ < Route path = "/projects/:slug" element = { < motion . div initial = "initial" animate = "in" exit = "out" variants = { pageVariants } transition = { pageTransition } > < ProjectPage /> </ motion . div > } />
41+ < Route path = "/about" element = { < motion . div initial = "initial" animate = "in" exit = "out" variants = { pageVariants } transition = { pageTransition } > < AboutPage /> </ motion . div > } />
42+ < Route path = "*" element = { < motion . div initial = "initial" animate = "in" exit = "out" variants = { pageVariants } transition = { pageTransition } > < NotFoundPage /> </ motion . div > } />
43+ </ Routes >
44+ </ AnimatePresence >
45+ ) ;
46+ }
47+
48+ export default AnimatedRoutes ;
0 commit comments