fix: 跳转不存在的路由空白页面问题修复

Former-commit-id: c797a3a474df0d0ec78daafff27f52e47d1d3777
This commit is contained in:
郝先瑞
2022-05-18 23:54:54 +08:00
parent 50c5c1ad2f
commit 14d7d879a0
2 changed files with 14 additions and 6 deletions

View File

@@ -69,7 +69,7 @@ import LangSelect from '@/components/LangSelect/index.vue';
// 图标依赖
import { CaretBottom } from '@element-plus/icons-vue';
const { app, user } = useStore();
const { app, user, tagsView } = useStore();
const route = useRoute();
const router = useRouter();
@@ -88,9 +88,14 @@ function logout() {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
user.logout().then(() => {
router.push(`/login?redirect=${route.fullPath}`);
});
user
.logout()
.then(() => {
tagsView.delAllViews();
})
.then(() => {
router.push(`/login?redirect=${route.fullPath}`);
});
});
}
</script>

View File

@@ -9,7 +9,6 @@ NProgress.configure({ showSpinner: false }); // 进度环显示/隐藏
const whiteList = ['/login', '/auth-redirect'];
router.beforeEach(async (to, from, next) => {
console.log('beforeEach', to);
NProgress.start();
const { user, permission } = useStore();
const hasToken = user.token;
@@ -21,7 +20,11 @@ router.beforeEach(async (to, from, next) => {
} else {
const hasGetUserInfo = user.roles.length > 0;
if (hasGetUserInfo) {
next();
if (to.matched.length === 0) {
from.name ? next({ name: from.name }) : next('/');
} else {
next();
}
} else {
try {
await user.getUserInfo();