front/src/utils/h5-redirect.ts
zzh 2dd3e656a3
All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m58s
feat: H5 访客可逛四 Tab,登录门禁与微信注册引导优化
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-26 10:22:58 +08:00

25 lines
868 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 解析 H5 登录/注册后的 redirect(可能含 query),供 router.replace 使用。
*/
export function parseH5RedirectLocation(redirect: string | null | undefined): {
path: string
query?: Record<string, string>
} {
const raw = String(redirect || '').trim()
if (!raw.startsWith('/h5') || raw.startsWith('/h5/admin')) {
return { path: '/h5/price' }
}
const hashIdx = raw.indexOf('#')
const withoutHash = hashIdx >= 0 ? raw.slice(0, hashIdx) : raw
const qIdx = withoutHash.indexOf('?')
if (qIdx < 0) {
return { path: withoutHash || '/h5/price' }
}
const path = withoutHash.slice(0, qIdx) || '/h5/price'
const query: Record<string, string> = {}
new URLSearchParams(withoutHash.slice(qIdx + 1)).forEach((value, key) => {
if (key) query[key] = value
})
return Object.keys(query).length ? { path, query } : { path }
}