1. Read the FAQs 馃憞
2. Describe the bug
I have problem with using Redirect in React router.
I use standart example with react-router and add Redirect component.
When i open url "/test", it correctly redirected to "/" but animation not started, and nothing happened
https://codesandbox.io/s/framer-motion-x-react-router-mu294
Steps to reproduce the behavior:
5. Expected behavior
Start animation of main page
I've run into this same issue today.
+1 here
I found a trick:
const MotionRedirect: React.FC<RedirectProps> = ({ children, ...props }) => (
<motion.div exit="undefined">
<Redirect {...props} />
</motion.div>
)
demo: https://codesandbox.io/s/react-router-framer-motion-dr4u6
v2 demo: https://codesandbox.io/s/framer-motion-v2-react-router-kisy4
same problem
I'm having this same issue in a case where a component will conditionally render a redirect. In a case where you directly navigate to the page by URL, the default usecase will cause the condition to return the redirect, and it has the same issue, once redirected the component doesn't show.
Using the workaround above solved this.
It is also an urgent problem for my case. Would be good if you guys can investigate the issue 馃檹 @InventingWithMonster
Thanks @lightyen !! Your answer was really helpful. I also was having issues with the <Redirect /> and <AnimatePresence /> components. And wrapping the <Redirect /> component into a <motion /> component with exit="undefined" did the trick. In my code, where I had defined my app routes, what I did was:
import { Fragment } from "react";
<AnimatePresence initial={false} exitBeforeEnter>
<Switch location={location} key={location.key}>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
<Route path="/not-found" component={NotFound} />
<motion.Fragment exit="undefined">
<Redirect to="/not-found" />
</motion.Fragment>
</Switch>
</AnimatePresence>
Most helpful comment
I found a trick:
demo: https://codesandbox.io/s/react-router-framer-motion-dr4u6
v2 demo: https://codesandbox.io/s/framer-motion-v2-react-router-kisy4