浏览器控制台上的错误
You're attempting to animate multiple children within AnimatePresence,
but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.

App.js (封装在BrowserRouter中)
<Switch>
<AnimatePresence exitBeforeEnter>
<Route key="1" exact path="/" component={Home}/>
<Route key="2" exact path="/home" component={Home}/>
<Route key="3" exact path="/articles" component={Articles}/>
</AnimatePresence>
</Switch>Home.js/Articles.js
const Home = props =>{
return(
<motion.h1 initial={{x:-100}} animate={{x:0}} exit={{x:-100}}>Home/Articles</motion.h1>
)
}
export default Articles有人能解释一下是什么原因造成的错误吗?
发布于 2020-09-02 10:29:31
就像医生说的关于exitBeforeEnter
如果
设置为true,AnimatePresence一次只能呈现一个组件。退出组件将在呈现输入组件之前完成其退出动画。
因此,在启用了这个支柱之后,您需要用另一种方式将Switch包装成AnimatePresence。
<AnimatePresence exitBeforeEnter>
<Switch location={location} key={location.pathname}>
<Route exact path="/" component={Home}/>
<Route exact path="/home" component={Home}/>
<Route exact path="/articles" component={Articles}/>
</Switch>
</AnimatePresence>请注意,您还需要为key传递Switch
https://stackoverflow.com/questions/63691903
复制相似问题