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 [view-transition-name:main-content]">
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 // see styles.css for 'warp' transition
29 viewTransition={{ types: ['warp'] }}
30 >
31 <div>{post.title.substring(0, 20)}</div>
32 </Link>
33 </li>
34 )
35 },
36 )}
37 </ul>
38 <hr />
39 <div className="[view-transition-name:post]">
40 <Outlet />
41 </div>
42 </div>
43 )
44}