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

posts.component.vue

32 lines870 Bytes

1<script setup lang="ts">
2import { Link, Outlet, useLoaderData } from '@tanstack/vue-router'
3import type { PostType } from '../posts'
4​
5const posts = useLoaderData({ from: '/posts' }) as unknown as Array<PostType>
6</script>
7​
8<template>
9 <div class="p-2 flex gap-2" data-testid="posts-links">
10 <ul class="list-disc pl-4">
11 <li
12 v-for="post in [
13 ...posts,
14 { id: 'i-do-not-exist', title: 'Non-existent Post' },
15 ]"
16 :key="post.id"
17 class="whitespace-nowrap"
18 >
19 <Link
20 to="/posts/$postId"
21 :params="{ postId: post.id }"
22 class="block py-1 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 </ul>
29 <hr />
30 <Outlet />
31 </div>
32</template>