mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-07 06:52:28 +00:00
feat(web): integrate TanStack React Router for client-side routing
Replace state-based screen navigation with proper URL-based routing. This includes: - New router configuration with routes for sessions, machines, and spawn pages - App context provider to share API and token across the app - useAppGoBack hook for handling browser and Telegram back navigation - Refactored App component to render outlet and use router hooks - Memory history for Telegram app, browser history for web
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { useCallback } from 'react'
|
||||
import { useLocation, useNavigate, useRouter } from '@tanstack/react-router'
|
||||
import { isTelegramApp } from '@/hooks/useTelegram'
|
||||
|
||||
export function useAppGoBack(): () => void {
|
||||
const navigate = useNavigate()
|
||||
const router = useRouter()
|
||||
const pathname = useLocation({ select: (location) => location.pathname })
|
||||
|
||||
return useCallback(() => {
|
||||
if (!isTelegramApp()) {
|
||||
router.history.back()
|
||||
return
|
||||
}
|
||||
|
||||
if (pathname.startsWith('/sessions/')) {
|
||||
navigate({ to: '/sessions' })
|
||||
return
|
||||
}
|
||||
|
||||
if (pathname.endsWith('/spawn')) {
|
||||
navigate({ to: '/machines' })
|
||||
return
|
||||
}
|
||||
|
||||
if (pathname.startsWith('/machines')) {
|
||||
navigate({ to: '/sessions' })
|
||||
}
|
||||
}, [navigate, pathname, router])
|
||||
}
|
||||
Reference in New Issue
Block a user