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

not-found.tsx

42 lines1.1 KB

1import { isNotFound } from '@tanstack/router-core'
2import { CatchBoundary } from './CatchBoundary'
3import { useRouterState } from './useRouterState'
4import type * as Solid from 'solid-js'
5import type { NotFoundError } from '@tanstack/router-core'
6​
7export function CatchNotFound(props: {
8 fallback?: (error: NotFoundError) => Solid.JSX.Element
9 onCatch?: (error: Error) => void
10 children: Solid.JSX.Element
11}) {
12 // TODO: Some way for the user to programmatically reset the not-found boundary?
13 const resetKey = useRouterState({
14 select: (s) => `not-found-${s.location.pathname}-${s.status}`,
15 })
16​
17 return (
18 <CatchBoundary
19 getResetKey={() => resetKey()}
20 onCatch={(error) => {
21 if (isNotFound(error)) {
22 props.onCatch?.(error)
23 } else {
24 throw error
25 }
26 }}
27 errorComponent={({ error }) => {
28 if (isNotFound(error)) {
29 return props.fallback?.(error)
30 } else {
31 throw error
32 }
33 }}
34 >
35 {props.children}
36 </CatchBoundary>
37 )
39​
40export function DefaultGlobalNotFound() {
41 return <p>Not Found</p>