Open History to see the last commit
1import * as React from 'react'
2import { ErrorComponent } from '@tanstack/react-router'
3import { fetchPost } from '../posts'
4import type { ErrorComponentProps } from '@tanstack/react-router'
5β
6export const Route = createFileRoute({
7 loader: async ({ params: { postId } }) => fetchPost(postId),
8 errorComponent: PostErrorComponent as any,
9 notFoundComponent: () => {
10 return <p>Post not found</p>
11 },
12 component: PostComponent,
13 codeSplitGroupings: [
14 ['component'],
15 ['pendingComponent', 'errorComponent', 'notFoundComponent'],
16 ],
17})
18β
19export function PostErrorComponent({ error }: ErrorComponentProps) {
20 return <ErrorComponent error={error} />
21}
22β
23function PostComponent() {
24 const post = Route.useLoaderData()
25β
26 return (
27 <div className="space-y-2">
28 <h4 className="text-xl font-bold underline">{post.title}</h4>
29 <div className="text-sm">{post.body}</div>
30 </div>
31 )
32}