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

error.tsx

29 lines712 Bytes

1import { createFileRoute } from '@tanstack/react-router'
2import * as React from 'react'
3​
4export const Route = createFileRoute('/error')({
5 component: ErrorComponent,
6 loader: () => {
7 if (Math.random() > 0.5) throw new Error('Random error!')
8 },
9 pendingComponent: () => <p>Loading..</p>,
10 wrapInSuspense: true,
11 errorComponent: ({ error }) => {
12 return (
13 <div className="p-2">
14 <h3>Caught: {error.message}</h3>
15 <p>(This page has a 75% chance of throwing an error)</p>
16 </div>
17 )
18 },
19})
20​
21function ErrorComponent() {
22 return (
23 <div className="p-2">
24 <h3>
25 The loader of this page will have a 75% chance of throwing an error!
26 </h3>
27 </div>
28 )