我正在尝试使用反应路由器 4 和 CSSTransitionGroup 为路由之间的过渡设置动画。似乎部分工作 - 进入组件有时会根据需要进行动画处理(但并非总是如此),退出组件会消失而没有过渡。这是未按预期运行的渲染函数:
render() {
/****************************************For transitions***********/
// const locationKey = this.props.location.pathname;
return (
<CSSTransitionGroup
key={this.props.location.key}
transitionName="flipIt"
transitionAppear={true}
transitionAppearTimeout={3000}
transitionEnterTimeout={3000}
transitionLeaveTimeout={3000}
>
<Switch key={this.props.location.pathname} location={this.props.location}>
<Route exact path='/' component={Welcome} />
<Route path='/game' render={(props) => (
<Board {...props} leaders={this.state.leaders} logGameGoes={this.setGameGoes} />
)} />
<Route path='/leaderboard' render={(props) => (
<Leaderboard {...props} leaders={this.state.leaders} syncLeaders={this.syncLeaders} />
)} />
<Route path='/winner' render={(props) => (
<Winner {...props} addLeader={this.addLeader} />
)} />
<Route path='/gameover' render={(props) => (
<Gameover {...props} goes={this.state.currentGameGoes} />
)} />
</Switch>
</CSSTransitionGroup>
);
}
}
export default withRouter(App);
整个应用程序可以在这个沙盒中看到: https ://codesandbox.io/s/vyn7zl2993
非常感谢您的帮助。