2 种解决方案:
1、 setTimeout 延时弹出
router.beforeEach((to, from, next) => {
if (storage.getSession('needLeaveTip')) {
// setTimeout 防止confirm 弹出又消失
setTimeout(() => {
MessageBox.confirm(i18n.t('public.needLeaveTip'), {
title: i18n.t('public.dialogTitle'),
type: 'warning'
}).then(() => {
window.onbeforeunload = null;
storage.clearOneSession('needLeaveTip');
next();
}).catch(() => {
next(false);
});
}, 100);
} else {
next();
}
NProgress.done();
});
2、mode: history 模式
tip: 可自行配置根路径参考
https://blog.csdn.net/github_36327470/article/details/106841359?spm=1001.2014.3001.5501
参考文章:
https://www.cnblogs.com/zffFighting/p/12965778.html
https://blog.csdn.net/weixin_46404395/article/details/123006658