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

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

@@ -6,7 +6,11 @@ import type { useAuthStore } from '@/stores/authStore'
type AuthStoreForGuard = ReturnType<typeof useAuthStore>
function createRoute(path: string, meta: Record<string, unknown> = {}): RouteLocationNormalized {
function createRoute(
path: string,
meta: Record<string, unknown> = {},
overrides: Partial<RouteLocationNormalized> = {},
): RouteLocationNormalized {
return {
fullPath: path,
path,
@@ -17,6 +21,7 @@ function createRoute(path: string, meta: Record<string, unknown> = {}): RouteLoc
matched: [],
meta,
redirectedFrom: undefined,
...overrides,
} as RouteLocationNormalized
}
@@ -113,4 +118,35 @@ describe('reservation router', () => {
await expect(guard(createRoute('/'))).resolves.toBe('/reservation/tasks')
expect(restored).toBe(true)
})
it('redirects the root route to the default page when the backend menu points to root', async () => {
const guard = createAuthGuard(() =>
createAuthStoreForGuard({
firstMenuPath: '/',
}),
)
await expect(guard(createRoute('/'))).resolves.toBe('/reservation/orders')
})
it('ignores root login redirects after authentication', async () => {
const guard = createAuthGuard(() => createAuthStoreForGuard())
await expect(
guard(
createRoute(
'/login',
{
public: true,
},
{
name: 'login',
query: {
redirect: '/',
},
},
),
),
).resolves.toBe('/reservation/orders')
})
})