Open History to see the last commit
1import { ErrorComponent, Link, createFileRoute } from '@tanstack/react-router'
2import { fetchPost } from '../utils/posts'
3import type { ErrorComponentProps } from '@tanstack/react-router'
4import { NotFound } from '~/components/NotFound'
5β
6export const Route = createFileRoute('/posts/$postId')({
7 loader: ({ params: { postId } }) => fetchPost({ data: postId }),
8 errorComponent: PostErrorComponent,
9 component: PostComponent,
10 notFoundComponent: () => {
11 return <NotFound>Post not found</NotFound>
12 },
13})
14β
15export function PostErrorComponent({ error }: ErrorComponentProps) {
16 return <ErrorComponent error={error} />
17}
18β
19function PostComponent() {
20 const post = Route.useLoaderData()
21β
22 return (
23 <div className="space-y-2">
24 <h4 className="text-xl font-bold underline">{post.title}</h4>
25 <div className="text-sm">{post.body}</div>
26 <Link
27 to="/posts/$postId/deep"
28 params={{
29 postId: post.id,
30 }}
31 activeProps={{ className: 'text-black font-bold' }}
32 className="inline-block py-1 text-blue-800 hover:text-blue-600"
33 >
34 Deep View
35 </Link>
36 </div>
37 )
38}