본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

페이지 링크

원문 보기 위키 갱신

페이지에 표시할 링크 목록을 보여주는 컴포넌트예요. 문서 페이지의 목차 아래나 사이드바에서 커뮤니티 관련 링크를 배치하는 데 유용합니다.

출처: Nuxt UI

본문

PageLinks 컴포넌트를 사용해 링크 목록을 표시해요.

<script setup lang="ts">
import type { PageLink } from '@nuxt/ui'

const links = ref<PageLink[]>([
  {
    label: "Edit this page",
    icon: "i-lucide-file-pen",
    to: "https://github.com/nuxt/ui/blob/v4/docs/content/docs/2.components/page-links.md"
  },
  {
    label: "Star on GitHub",
    icon: "i-lucide-star",
    to: "https://github.com/nuxt/ui"
  },
  {
    label: "Releases",
    icon: "i-lucide-rocket",
    to: "https://github.com/nuxt/ui/releases"
  }
])
</script>

<template>
  <UPageLinks :links="links" />
</template>

links prop을 아래 속성을 가진 객체 배열로 사용해 주세요:

  • label: string
  • icon?: string
  • class?: any
  • ui?: { item?: ClassNameValue, link?: ClassNameValue, linkLabel?: ClassNameValue, linkLabelExternalIcon?: ClassNameValue, linkLeadingIcon?: ClassNameValue }

Link 컴포넌트의 to, target 등 어떤 속성이든 전달할 수 있어요.

<script setup lang="ts">
import type { PageLink } from '@nuxt/ui'

const links = ref<PageLink[]>([
  {
    label: "Edit this page",
    icon: "i-lucide-file-pen",
    to: "https://github.com/nuxt/ui/blob/v4/docs/content/docs/2.components/page-links.md"
  },
  {
    label: "Star on GitHub",
    icon: "i-lucide-star",
    to: "https://github.com/nuxt/ui"
  },
  {
    label: "Releases",
    icon: "i-lucide-rocket",
    to: "https://github.com/nuxt/ui/releases"
  }
])
</script>

<template>
  <UPageLinks :links="links" />
</template>

제목 (Title)

title prop을 사용해 링크 위에 제목을 표시해요.

<script setup lang="ts">
import type { PageLink } from '@nuxt/ui'

const links = ref<PageLink[]>([
  {
    label: "Edit this page",
    icon: "i-lucide-file-pen",
    to: "https://github.com/nuxt/ui/blob/v4/docs/content/docs/2.components/page-links.md"
  },
  {
    label: "Star on GitHub",
    icon: "i-lucide-star",
    to: "https://github.com/nuxt/ui"
  },
  {
    label: "Releases",
    icon: "i-lucide-rocket",
    to: "https://github.com/nuxt/ui/releases"
  }
])
</script>

<template>
  <UPageLinks title="Community" :links="links" />
</template>

예시 (Examples)

[!NOTE]

이 예시들은 Nuxt Content를 사용하지만, 컴포넌트는 어떤 콘텐츠 관리 시스템과도 통합할 수 있어요.

페이지 안에서 사용 (Within a page)

ContentToc 컴포넌트의 bottom 슬롯 안에 PageLinks 컴포넌트를 넣어 목차 아래에 링크 목록을 표시해요.

<script setup lang="ts">
import type { PageLink } from '@nuxt/ui'

const route = useRoute()

definePageMeta({
  layout: 'docs'
})

const { data: page } = await useAsyncData(route.path, () => {
  return queryCollection('docs').path(route.path).first()
})

const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
  return queryCollectionItemSurroundings('content', route.path)
})

const links = computed<PageLink[]>(() => [{
  icon: 'i-lucide-file-pen',
  label: 'Edit this page',
  to: `https://github.com/nuxt/ui/edit/v4/docs/content/${page?.value?.stem}.md`,
  target: '_blank'
}, {
  icon: 'i-lucide-star',
  label: 'Star on GitHub',
  to: 'https://github.com/nuxt/ui',
  target: '_blank'
}, {
  label: 'Releases',
  icon: 'i-lucide-rocket',
  to: 'https://github.com/nuxt/ui/releases'
}])
</script>

<template>
  <UPage>
    <UPageHeader :title="page.title" :description="page.description" />

    <UPageBody>
      <ContentRenderer :value="page" />

      <USeparator />

      <UContentSurround :surround="surround" />
    </UPageBody>

    <template #right>
      <UContentToc :links="page.body.toc.links">
        <template #bottom>
          <USeparator type="dashed" />

          <UPageLinks title="Community" :links="links" />
        </template>
      </UContentToc>
    </template>
  </UPage>
</template>

API

Props

/**
 * Props for the PageLinks component
 */
interface PageLinksProps {
  /**
   * The element or component this component should render as.
   * @default 'nav'
   */
  as?: any;
  title?: string | undefined;
  links?: T[] | undefined;
  ui?: { root?: SlotClass; title?: SlotClass; list?: SlotClass; item?: SlotClass; link?: SlotClass; linkLeadingIcon?: SlotClass; linkLabel?: SlotClass; linkLabelExternalIcon?: SlotClass; } | undefined;
}

Slots

/**
 * Slots for the PageLinks component
 */
interface PageLinksSlots {
  title(): any;
  link(): any;
  link-leading(): any;
  link-label(): any;
  link-trailing(): any;
}

테마 (Theme)

export default defineAppConfig({
  ui: {
    pageLinks: {
      slots: {
        root: 'flex flex-col gap-3',
        title: 'text-sm font-semibold flex items-center gap-1.5',
        list: 'flex flex-col gap-2',
        item: 'relative',
        link: 'group text-sm flex items-center gap-1.5 rounded-sm outline-primary/25 focus-visible:outline-3',
        linkLeadingIcon: 'size-5 shrink-0',
        linkLabel: 'truncate',
        linkLabelExternalIcon: 'size-3 absolute top-0 text-dimmed'
      },
      variants: {
        active: {
          true: {
            link: 'text-primary font-medium'
          },
          false: {
            link: [
              'text-muted hover:text-default',
              'transition-colors'
            ]
          }
        }
      }
    }
  }
})

변경 기록 (Changelog)

컴포넌트와 테마의 커밋 내역을 확인해 보세요.

더 알아보기 (Learn more)