umi路由跳转问题
- 描述一下问题,有一个需求就是要记录页面缓存,跳到其他页面的时候,当通过goBack、或者是history.go(-1)返回的时候,保存当前页面的筛选条件,以及页码。
- 或者要离开当前页面的时候,需要做一下提醒。
解决方式
- hooks,监听当前页面的props.history.location变化
useEffect(() => {
if (props.history.location.pathname === '/O2OBusinessManger' && props.history.location.action === 'POP') {
console.log('执行');
}
}, [props.history.location]);
- Umi history.block 的实现
history.block((location, action) => {
if (location.pathname === '/O2OBusinessManger' && action === 'POP') {
console.log('提示');
}
})
- Umi API Prompt (当页面离开提示)
import { Prompt } from 'umi';
export default () => {
return (
<div>
<Prompt message="你确定要离开么?" />
</div>
);
};
写一篇有用的文章不容易欢迎打赏与讨论