0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
router/docs/framework/react/api/router/catchNotFoundComponent.md
2024-05-18 23:43:29 +02:00

1.2 KiB

id title
catchNotFoundComponent CatchNotFound Component

The CatchNotFound component is a component that catches not-found errors thrown by its children, renders a fallback component and optionally calls the onCatch callback. It resets when the pathname changes.

CatchNotFound props

The CatchNotFound component accepts the following props:

props.children prop

  • Type: React.ReactNode
  • Required
  • The component's children to render when there is no error

props.fallback prop

  • Type: (error: NotFoundError) => React.ReactElement
  • Optional
  • The component to render when there is an error

props.onCatch prop

  • Type: (error: any) => void
  • Optional
  • A callback that will be called with the error that was thrown by the component's children

CatchNotFound returns

  • Returns the component's children if there is no error.
  • Returns the fallback if there is an error.

Examples

import { CatchNotFound } from '@tanstack/react-router'

function Component() {
  return (
    <CatchNotFound
      fallback={(error) => <p>Not found error! {JSON.stringify(error)}</p>}
    >
      <ComponentThatMightThrowANotFoundError />
    </CatchNotFound>
  )
}