修复登录后首页入口跳转问题

This commit is contained in:
andy
2026-07-10 10:28:04 +08:00
parent 25efcccf72
commit 9de4f0e7b6
8 changed files with 132 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ import { createRouter, createWebHistory, type RouteLocationNormalized } from 'vu
import { useAuthStore } from '@/stores/authStore'
import type { AuthPermissionCode } from '@/types/auth'
import { resolveAuthenticatedEntryPath, resolveLoginRedirectPath } from '@/utils/authNavigation'
type AuthStore = ReturnType<typeof useAuthStore>
type AppRouteMeta = {
@@ -113,7 +114,7 @@ export function createAuthGuard(resolveAuthStore: () => AuthStore = () => useAut
if (meta.public) {
if (to.name === 'login' && authStore.isAuthenticated) {
return safeRedirectPath(to.query.redirect) ?? authStore.firstMenuPath ?? '/reservation/orders'
return resolveLoginRedirectPath(to.query.redirect, authStore.firstMenuPath)
}
return true
}
@@ -128,7 +129,7 @@ export function createAuthGuard(resolveAuthStore: () => AuthStore = () => useAut
}
if (to.path === '/') {
return authStore.firstMenuPath ?? '/reservation/orders'
return resolveAuthenticatedEntryPath(authStore.firstMenuPath)
}
if (meta.permission && !authStore.hasPermission(meta.permission)) {
@@ -140,13 +141,3 @@ export function createAuthGuard(resolveAuthStore: () => AuthStore = () => useAut
return true
}
}
function safeRedirectPath(redirect: unknown): string | null {
if (typeof redirect !== 'string') {
return null
}
if (!redirect.startsWith('/') || redirect.startsWith('//') || redirect.startsWith('/login')) {
return null
}
return redirect
}