Open History to see the last commit
1import { Link, createFileRoute } from '@tanstack/react-router'
2import { useSuspenseQuery } from '@tanstack/react-query'
3import { postQueryOptions } from '../utils/posts'
4import { PostErrorComponent } from './posts.$postId'
5β
6export const Route = createFileRoute('/posts_/$postId/deep')({
7 loader: async ({ params: { postId }, context }) => {
8 const data = await context.queryClient.ensureQueryData(
9 postQueryOptions(postId),
10 )
11β
12 return {
13 title: data.title,
14 }
15 },
16 head: ({ loaderData }) => ({
17 meta: loaderData ? [{ title: loaderData.title }] : undefined,
18 }),
19 errorComponent: PostErrorComponent,
20 component: PostDeepComponent,
21})
22β
23function PostDeepComponent() {
24 const { postId } = Route.useParams()
25 const postQuery = useSuspenseQuery(postQueryOptions(postId))
26β
27 return (
28 <div className="p-2 space-y-2">
29 <Link
30 to="/posts"
31 className="block py-1 text-blue-800 hover:text-blue-600"
32 >
33 β All Posts
34 </Link>
35 <h4 className="text-xl font-bold underline">{postQuery.data.title}</h4>
36 <div className="text-sm">{postQuery.data.body}</div>
37 </div>
38 )
39}