修复登录后首页入口跳转问题
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user