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

posts.tsx

39 lines1.0 KB

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