From 5118598d837fba1ebfcdc0457292a17aefd465ab Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 19 Jan 2026 14:11:26 +0800 Subject: [PATCH] 1 --- src/layout/components/Navbar.vue | 2 +- src/views/login.vue | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index a476e72..59cab21 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -86,7 +86,7 @@ export default { type: 'warning' }).then(() => { this.$store.dispatch('LogOut').then(() => { - location.href = '/index' + this.$router.push('/login') }) }).catch(() => {}) } diff --git a/src/views/login.vue b/src/views/login.vue index c221563..e0ec45b 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -144,9 +144,16 @@ export default { Cookies.remove('rememberMe') } this.$store.dispatch("Login", this.loginForm).then(() => { - // 使用 replace 而不是 push,避免路由历史问题 - this.$nextTick(() => { - window.location.href = this.redirect || "/sloworder/index" + // 先获取用户信息和生成路由,然后再跳转 + this.$store.dispatch('GetInfo').then(() => { + this.$store.dispatch('GenerateRoutes').then(() => { + // 使用 replace 而不是 push,避免路由历史问题 + const redirectPath = this.redirect || "/sloworder/index" + this.$router.replace(redirectPath).catch(() => { + // 如果目标路由不存在,跳转到默认路由 + this.$router.replace("/sloworder/index") + }) + }) }) }).catch(() => { this.loading = false