feat(mobile): 重构移动端首页与个人中心
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { useLayoutEffect } from 'react'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
|
||||
import {
|
||||
getMobilePath,
|
||||
isMobileDevice,
|
||||
prefersDesktopSite,
|
||||
setDesktopPreference,
|
||||
} from '@/shared/utils/mobileHost'
|
||||
|
||||
export function MobileRouteGate() {
|
||||
const location = useLocation()
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const params = new URLSearchParams(location.search)
|
||||
if (params.get('desktop') === '1') {
|
||||
setDesktopPreference(true)
|
||||
params.delete('desktop')
|
||||
const search = params.toString()
|
||||
window.location.replace(`${location.pathname}${search ? `?${search}` : ''}${location.hash}`)
|
||||
return
|
||||
}
|
||||
|
||||
if (prefersDesktopSite() || !isMobileDevice()) return
|
||||
|
||||
const mobilePath = getMobilePath(location.pathname)
|
||||
if (mobilePath === location.pathname) return
|
||||
|
||||
window.location.replace(`${mobilePath}${location.search}${location.hash}`)
|
||||
}, [location.hash, location.pathname, location.search])
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user