Open History to see the last commit
1import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
2import { fetchPosts } from '../utils/posts'
3β
4export const Route = createFileRoute('/posts')({
5 loader: async () => fetchPosts(),
6 component: PostsComponent,
7})
8β
9function PostsComponent() {
10 const posts = Route.useLoaderData()
11β
12 return (
13 <div className="p-2 flex gap-2">
14 <ul className="list-disc pl-4">
15 {[...posts, { id: 'i-do-not-exist', title: 'Non-existent Post' }].map(
16 (post) => {
17 return (
18 <li key={post.id} className="whitespace-nowrap">
19 <Link
20 to="/posts/$postId"
21 params={{
22 postId: post.id,
23 }}
24 className="block py-1 text-blue-800 hover:text-blue-600"
25 activeProps={{ className: 'text-black font-bold' }}
26 >
27 <div>{post.title.substring(0, 20)}</div>
28 </Link>
29 </li>
30 )
31 },
32 )}
33 </ul>
34 <hr />
35 <Outlet />
36 </div>
37 )
38}