refactor: 改用router.push并清除路由守卫缓存替代window.location.href
- 添加resetInstallCheck()清除安装状态缓存 - 安装完成后调用resetInstallCheck再router.push跳转 - 保持SPA无刷新体验
This commit is contained in:
@@ -4,6 +4,8 @@ import { computed, onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { toast } from 'vue-sonner'
|
||||
|
||||
import { resetInstallCheck } from '@/router/guard/index'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const loading = ref(false)
|
||||
@@ -42,7 +44,8 @@ async function checkInstallStatus() {
|
||||
const data = await res.json()
|
||||
installStatus.value = data?.data
|
||||
if (data?.data?.installed) {
|
||||
window.location.href = '/login'
|
||||
resetInstallCheck()
|
||||
router.push('/login')
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
@@ -162,7 +165,8 @@ function goNext() {
|
||||
}
|
||||
|
||||
function goLogin() {
|
||||
window.location.href = '/login'
|
||||
resetInstallCheck()
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -3,6 +3,11 @@ import type { Router } from 'vue-router'
|
||||
let installChecked = false
|
||||
let isInstalled = false
|
||||
|
||||
export function resetInstallCheck() {
|
||||
installChecked = false
|
||||
isInstalled = false
|
||||
}
|
||||
|
||||
async function checkInstallStatus(): Promise<boolean> {
|
||||
if (installChecked) return isInstalled
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user