需求要点击页面导航,组件有动画展示效果
这里我找到了一个React的官方动画库react-transition-group
npm i -S react-transition-group
import { CSSTransition, TransitionGroup } from 'react-transition-group';
<TransitionGroup>
<CSSTransition
key={window.location.pathname}
timeout={300}
classNames="page"
unmountOnExit
>
<Routes >
<Route path='' element={<Information />}></Route>
<Route path='/Index' element={<Information />}></Route>
<Route path='/Index/AerationControl' element={<AerationControl />}></Route>
<Route path='/Index/AlarmManagement' element={<AlarmManagement/>}></Route>
<Route path='/Index/SystemManagement' element={<SystemManagement/>}> </Route>
</Routes>
</CSSTransition>
</TransitionGroup>
// 页面切换过渡动画
.page {
position: absolute;
left: 15px;
right: 15px;
}
// 页面切换过渡动画 --- 进入
.page-enter {
opacity: 0;
transform: translateY(100%);
}
// 页面切换过渡动画 --- 进入(被激活)
.page-enter-active {
opacity: 1;
// transform: scale(1);
transform: translateY(0);
transition: opacity 300ms, transform 300ms;
}
// 页面切换过渡动画 --- 离开
.page-exit {
opacity: 1;
transform: translateY(0%);
}
// 页面切换过渡动画 --- 离开(被激活)
.page-exit-active {
opacity: 0;
transform: translateY(100%);
transition: opacity 300ms, transform 300ms;
}
<TransitionGroup>
<CSSTransition>
用这两个将路由包住
这样就会使点击的导航路由有动画效果了