我正在使用react-transition-group的标签在使用react-router-v4的路由之间创建动画。我使用标签在我的代码中根据状态的变化在路由之间切换。我遇到的问题是,当a被触发时,组件会立即卸载,然后才有退出动画播放的时间。新管线将正确设置动画。
我试图通过在React Transition Group站点上关注这个页面来解决这个问题:https://reactcommunity.org/react-transition-group/with-react-router
它承认我在卸载组件时遇到的问题,但我的解决方案似乎不起作用。
const routes = [
{ path: '/', name: 'Dashboard', Component: Dashboard },
{ path: '/detailedview', name: 'DetailedView', Component: DetailedView },
{ path: '/dashboardloop', name: 'DashboardLoop', Component: DashboardLoop },
]
function Example() {
return (
<Router>
<>
<Container className="container">
{routes.map(({ path, Component }) => (
<Route key={path} exact path={path}>
{({ match }) => (
<CSSTransition
in={match != null}
timeout={500}
classNames="page"
unmountOnExit
>
<div className="page">
<Component />
</div>
</CSSTransition>
)}
</Route>
))}
</Container>
</>
</Router>
)
}
ReactDOM.render((
<Example/>
), document.getElementById('root'));对此任何帮助都将不胜感激!谢谢
发布于 2020-07-23 22:16:06
晚到派对上,你可能已经自己解决了这个问题,但为了记录在案,人们在谷歌上搜索这个问题:检查你的css。
CSSTransition依赖于四个css类(如文档中所述):
/* Starting style of enter animation, i.e when element is still invisible */
.page-transition-enter{
}
/* How the element will look on the page + transition (which does the animation) goes here*/
.page-transition-enter-active{
}
/* Start of exit animation, usually how the element looks on the page */
.page-transition-exit{
}
/*The end-style of exit-animation + transition */
.page-transition-exit-active{
}React transition Group documentation (http://reactcommunity.org/react-transition-group/css-transition)中的一个简单转换示例:
.page-enter {
opacity: 0;
}
.page-enter-active {
opacity: 1;
transition: opacity 200ms;
}
.page-exit {
opacity: 1;
}
.page-exit-active {
opacity: 0;
transition: opacity 200ms;
}当你的元素在没有动画的情况下卸载,但在进入时是动画的,似乎你很可能从最后两个类中遗漏了一些东西。或者完全缺少任何一个类或两个类。
https://stackoverflow.com/questions/57204090
复制相似问题