All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m58s
Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
868 B
TypeScript
25 lines
868 B
TypeScript
/**
|
||
* 解析 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 }
|
||
}
|