我有以下代码:
import React from "react";
import { BrowserRouter, Route, NavLink } from "react-router-dom";
import { AnimatePresence, motion } from "framer-motion";
import Hi from "./Hi";
import Something from "./Something";
import "./App.css";
const App = () => {
return (
<BrowserRouter>
<AnimatePresence>
<NavLink to="/">Hi</NavLink>
<br />
<NavLink to="/something">Something</NavLink>
<hr />
<Route path="/" exact={true} key="1">
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 2 }}
key="hi"
>
<Hi />
</motion.div>
</Route>
<Route path="/something" exact={true} key="2">
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
key="something"
transition={{ duration: 2 }}
>
<Something />
</motion.div>
</Route>
</AnimatePresence>
</BrowserRouter>
);
};
export default App;
假设它必须在安装 and 时执行淡入动画,并在卸载时淡出。安装动画发生,但另一个没有。在动画效果开始之前,这两个组件都已卸载,并且所有动画库都会出现问题:、和其他。<Hi/>
<Something/>
framer-motion
react-transition-group