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

posts_.$postId.deep.tsx

29 lines770 Bytes

1import { Link, createFileRoute } from '@tanstack/react-router'
2import { fetchPost } from '../utils/posts'
3import { PostErrorComponent } from './posts.$postId'
4​
5export const Route = createFileRoute('/posts_/$postId/deep')({
6 loader: ({ params: { postId } }) =>
7 fetchPost({
8 data: postId,
9 }),
10 errorComponent: PostErrorComponent,
11 component: PostDeepComponent,
12})
13​
14function PostDeepComponent() {
15 const post = Route.useLoaderData()
16​
17 return (
18 <div className="p-2 space-y-2">
19 <Link
20 to="/posts"
21 className="block py-1 text-blue-800 hover:text-blue-600"
22 >
23 ← All Posts
24 </Link>
25 <h4 className="text-xl font-bold underline">{post.title}</h4>
26 <div className="text-sm">{post.body}</div>
27 </div>
28 )