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