irychen / keepalive-for-react

React KeepAlive is a component that can cache the state of the component and reuse it when needed.
MIT License
189 stars 34 forks source link

react-transition-group CSSTransition 包裹 Keepalive 不生效 #9

Closed yibird closed 5 months ago

yibird commented 5 months ago

目前是试过各种办法,都没有办法实现过渡和缓存效果:

  1. Keepalive 包裹 CSSTransition:这种情况会导致outlet渲染有问题,outlet渲染的是根据菜单数据动态加载的路由。
  2. 使用Keepalive包裹动态渲染的路由,这种情况下不使用CSSTransition包裹Keepalive是生效的,否则缓存无效
irychen commented 5 months ago

./style.css

.keep-alive-render {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.cache-component {
    width: 100%;
    height: 100%;
    overflow: auto;
}

@keyframes slide-in {
    from {
        transform: scale(0.8);
    }
    to {
        transform: scale(1);
    }
}

@keyframes fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.cache-component {
    animation:
        fade-in 0.3s ease-in-out,
        slide-in 0.3s ease-in-out;
}
irychen commented 5 months ago

效果例子

https://irychen.github.io/super-admin/#/login