Closed Jordonwang closed 4 months ago
路由中需要这样使用
import {useLocation, useOutlet} from 'react-router-dom';
function BasicLayoutWithCache() {
const outlet = useOutlet();
const location = useLocation();
/**
* to distinguish different pages to cache
*/
const cacheKey = useMemo(() => {
return location.pathname + location.search;
}, [location]);
return <div>
<KeepAlive activeName={cacheKey} max={10} strategy={'LRU'}>
{outlet}
</KeepAlive>
</div>
}