hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { useCanGoBack, useLocation, useNavigate, useRouter } from "@tanstack/solid-router"; |
| 2 | import { backTarget } from "@/lib/back-target"; |
| 3 | |
| 4 | /** |
| 5 | * Back within the app: history when there is an in-app entry behind us, the |
| 6 | * nearest existing parent route otherwise. The browser's own back on a deep |
| 7 | * link or a fresh tab would leave the app. |
| 8 | */ |
| 9 | export function useGoBack(): () => void { |
| 10 | const router = useRouter(); |
| 11 | const canGoBack = useCanGoBack(); |
| 12 | const location = useLocation(); |
| 13 | const navigate = useNavigate(); |
| 14 | return () => { |
| 15 | if (canGoBack()) return router.history.back(); |
| 16 | void navigate({ to: backTarget(location().pathname, Object.keys(router.routesByPath)) }); |
| 17 | }; |
| 18 | } |