Open History to see the last commit
1import { Link, Outlet, createFileRoute } from '@tanstack/solid-router'
2import { For } from 'solid-js'
3β
4import { fetchPosts } from '~/utils/posts'
5β
6export const Route = createFileRoute('/posts')({
7 head: () => ({
8 meta: [
9 {
10 title: 'Posts page',
11 },
12 ],
13 }),
14 loader: async () => fetchPosts(),
15 component: PostsComponent,
16})
17β
18function PostsComponent() {
19 const posts = Route.useLoaderData()
20β
21 return (
22 <div class="p-2 flex gap-2">
23 <ul class="list-disc pl-4">
24 <For each={posts()}>
25 {(post) => {
26 return (
27 <li class="whitespace-nowrap">
28 <Link
29 to="/posts/$postId"
30 params={{
31 postId: post.id,
32 }}
33 class="block py-1 text-blue-800 hover:text-blue-600"
34 activeProps={{ class: 'text-black font-bold' }}
35 >
36 <div>{post.title.substring(0, 20)}</div>
37 </Link>
38 </li>
39 )
40 }}
41 </For>
42 </ul>
43 <hr />
44 <Outlet />
45 </div>
46 )
47}