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