修复登录后首页入口跳转问题
This commit is contained in:
27
client/src/utils/authNavigation.ts
Normal file
27
client/src/utils/authNavigation.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export const DEFAULT_AUTHENTICATED_ROUTE = '/reservation/orders'
|
||||
|
||||
export function normalizeAuthenticatedRoutePath(path: unknown): string | null {
|
||||
if (typeof path !== 'string') {
|
||||
return null
|
||||
}
|
||||
const trimmedPath = path.trim()
|
||||
if (!trimmedPath.startsWith('/') || trimmedPath.startsWith('//')) {
|
||||
return null
|
||||
}
|
||||
const [pathOnly = ''] = trimmedPath.split(/[?#]/, 1)
|
||||
if (pathOnly === '/' || pathOnly.startsWith('/login')) {
|
||||
return null
|
||||
}
|
||||
return trimmedPath
|
||||
}
|
||||
|
||||
export function resolveAuthenticatedEntryPath(firstMenuPath: string | null | undefined): string {
|
||||
return normalizeAuthenticatedRoutePath(firstMenuPath) ?? DEFAULT_AUTHENTICATED_ROUTE
|
||||
}
|
||||
|
||||
export function resolveLoginRedirectPath(
|
||||
redirect: unknown,
|
||||
firstMenuPath: string | null | undefined,
|
||||
): string {
|
||||
return normalizeAuthenticatedRoutePath(redirect) ?? resolveAuthenticatedEntryPath(firstMenuPath)
|
||||
}
|
||||
Reference in New Issue
Block a user