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

posts.lazy.tsx

35 lines969 Bytes

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