fix(web): fix navigation in session creation flow with back buttons

- Add back buttons to MachinesPage and SpawnPage for non-Telegram environments
- Fix navigation after session creation to clear spawn flow from history
- Update useAppGoBack hook to use explicit path navigation for consistent behavior
This commit is contained in:
weishu
2025-12-21 23:55:33 +08:00
parent 04725dda72
commit 16c2e7c7ec
2 changed files with 53 additions and 9 deletions
+5 -6
View File
@@ -1,6 +1,5 @@
import { useCallback } from 'react'
import { useLocation, useNavigate, useRouter } from '@tanstack/react-router'
import { isTelegramApp } from '@/hooks/useTelegram'
export function useAppGoBack(): () => void {
const navigate = useNavigate()
@@ -8,11 +7,7 @@ export function useAppGoBack(): () => void {
const pathname = useLocation({ select: (location) => location.pathname })
return useCallback(() => {
if (!isTelegramApp()) {
router.history.back()
return
}
// Use explicit path navigation for consistent behavior across all environments
if (pathname.startsWith('/sessions/')) {
navigate({ to: '/sessions' })
return
@@ -25,6 +20,10 @@ export function useAppGoBack(): () => void {
if (pathname.startsWith('/machines')) {
navigate({ to: '/sessions' })
return
}
// Fallback to history.back() for other cases
router.history.back()
}, [navigate, pathname, router])
}