{"id":7824,"date":"2023-05-26T12:33:43","date_gmt":"2023-05-26T11:33:43","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=7824"},"modified":"2023-06-20T08:57:47","modified_gmt":"2023-06-20T07:57:47","slug":"react-page-animations-with-framer-motion","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/react-page-animations-with-framer-motion\/","title":{"rendered":"React Page Animations with Framer Motion"},"content":{"rendered":"\n<p>The key to get it working is:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Wrap the &lt;Routes&gt; element in a &lt;AnimatePresence&gt; element<\/li>\n\n\n\n<li>Add key={location.pathname} location={location} to the &lt;Routes> element<\/li>\n\n\n\n<li>Use a &lt;motion.div> (or similar element) within your route (content) element<\/li>\n<\/ul>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"tsx\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import React from \"react\";\nimport { Routes, Route, useLocation } from \"react-router-dom\";\nimport Home from \".\/Home\";\nimport Contact from \".\/Contact\";\nimport About from \".\/About\";\nimport { AnimatePresence } from \"framer-motion\";\n\nexport function AnimatedRoutes(props: {}) {\n    const location = useLocation();\n    \n    return (\n    &lt;AnimatePresence>\n        &lt;Routes key={location.pathname} location={location}>\n            &lt;Route path=\"\/\" element={&lt;Home \/>} \/>\n            &lt;Route path=\"\/home\" element={&lt;Home \/>} \/>\n            &lt;Route path=\"\/about\" element={&lt;About \/>} \/>\n            &lt;Route path=\"\/contact\" element={&lt;Contact \/>} \/>\n        &lt;\/Routes>\n    &lt;\/AnimatePresence>\n    );\n}\n\n\nexport function App(props: {}) {\n    \/* HashRouter or BrowserRouter *\/\n    return (&lt;div>\n        &lt;HashRouter> \n            &lt;AnimatedRoutes \/>\n        &lt;\/HashRouter>\n    &lt;\/div>)\n}\n<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The key to get it working is:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7824","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/7824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=7824"}],"version-history":[{"count":4,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/7824\/revisions"}],"predecessor-version":[{"id":7876,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/7824\/revisions\/7876"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=7824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=7824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=7824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}