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

posts.tsx

46 lines1.2 KB

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