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