fix(web): 修复路由守卫 next 弃用警告

将全局导航守卫改为返回值式跳转,避免 Vue Router 提示 next 回调已弃用。
This commit is contained in:
Wenjie Zhang 2026-05-10 18:56:24 +08:00
parent 22fbcb586c
commit c44085d718
3 changed files with 12 additions and 15 deletions

View File

@ -188,7 +188,7 @@ const router = createRouter({
})
// 全局前置守卫
router.beforeEach(async (to, from, next) => {
router.beforeEach(async (to) => {
// 检查路由是否需要认证
const requiresAuth = to.matched.some((record) => record.meta.requiresAuth === true)
const requiresAdmin = to.matched.some((record) => record.meta.requiresAdmin)
@ -215,8 +215,7 @@ router.beforeEach(async (to, from, next) => {
if (requiresAuth && !isLoggedIn) {
// 保存尝试访问的路径,登录后跳转
sessionStorage.setItem('redirect', to.fullPath)
next('/login')
return
return '/login'
}
// 如果路由需要管理员权限但用户不是管理员
@ -228,12 +227,11 @@ router.beforeEach(async (to, from, next) => {
if (!agentStore.isInitialized) {
await agentStore.initialize()
}
next('/agent')
return '/agent'
} catch (error) {
console.error('获取智能体信息失败:', error)
next('/agent')
return '/agent'
}
return
}
// 如果路由需要超级管理员权限但用户不是超级管理员
@ -243,22 +241,20 @@ router.beforeEach(async (to, from, next) => {
if (!agentStore.isInitialized) {
await agentStore.initialize()
}
next('/agent')
return '/agent'
} catch (error) {
console.error('获取智能体信息失败:', error)
next('/agent')
return '/agent'
}
return
}
// 如果用户已登录但访问登录页
if (to.path === '/login' && isLoggedIn) {
next('/')
return
return '/'
}
// 其他情况正常导航
next()
return true
})
export default router

View File

@ -206,7 +206,8 @@ import {
SyncOutlined,
SearchOutlined,
ReloadOutlined,
LoadingOutlined
LoadingOutlined,
DatabaseOutlined
} from '@ant-design/icons-vue'
import PageHeader from '@/components/shared/PageHeader.vue'
import { neo4jApi, unifiedApi } from '@/apis/graph_api'

View File

@ -591,8 +591,8 @@ onMounted(loadProviders)
<Plus :size="14" />
新增供应商
</a-button>
<a-button class="lucide-icon-btn" @click="refreshProviders" :loading="refreshing">
<RefreshCw :size="14" :class="{ spinning: refreshing }" />
<a-button class="lucide-icon-btn" @click="loadProviders" :loading="loading">
<RefreshCw :size="14" :class="{ spinning: loading }" />
</a-button>
</template>
</PageShoulder>