尝试让预加载器显示、淡出,然后显示新路由。该怎么做呢?现在页面正在闪烁,然后预加载器显示,并淡出到新的路由。
我正在尝试使用带有useEffect(() => {...},location)的useLocation,但是它导致了闪光。
在路由器级别,我让它在主体中添加一个加载类,以便预加载器显示出来。一旦安装了路由组件,我就会删除那个类。但是,在路径渲染之后,触发位置更改的useEffect似乎正在被调用。
发布于 2020-12-11 00:26:11
好的,这看起来已经修复了,这是我之前的代码。
useEffect(() => {
document.body.classList.remove('loaded');
window.scrollTo(0, 0);
const currentPath = location.pathname + location.search;
analytics.sendPageview(currentPath);
setTimeout(function () {
document.body.classList.add("loaded");
}, 1000);
}, [location]);这是我切换到的修复它的代码。
useEffect(() => {
return history.listen(location => {
document.body.classList.remove('loaded');
setTimeout(function () {
document.body.classList.add("loaded");
}, 1000);
})
}, [history])https://stackoverflow.com/questions/65238177
复制相似问题