Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

DefaultCatchBoundary.tsx

54 lines1.4 KB

1import * as React from 'react'
2import {
3 ErrorComponent,
4 Link,
5 rootRouteId,
6 useMatch,
7 useRouter,
8} from '@tanstack/react-router'
9import type { ErrorComponentProps } from '@tanstack/react-router'
10​
11export function DefaultCatchBoundary({ error }: ErrorComponentProps) {
12 const router = useRouter()
13 const isRoot = useMatch({
14 strict: false,
15 select: (state) => state.id === rootRouteId,
16 })
17​
18 console.error(error)
19​
20 return (
21 <div className="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6">
22 <ErrorComponent error={error} />
23 <div className="flex gap-2 items-center flex-wrap">
24 <button
25 onClick={() => {
26 router.invalidate()
27 }}
28 className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`}
29 >
30 Try Again
31 </button>
32 {isRoot ? (
33 <Link
34 to="/"
35 className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`}
36 >
37 Home
38 </Link>
39 ) : (
40 <Link
41 to="/"
42 className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`}
43 onClick={(e) => {
44 e.preventDefault()
45 window.history.back()
46 }}
47 >
48 Go Back
49 </Link>
50 )}
51 </div>
52 </div>
53 )