@fiscozen/link

中文文档
1.0.1发布于 2026/04/30MITES Module零依赖近 30 天下载 2338

Design System Link component

原始使用文档
文档目录19 节
  1. Features
  2. Installation
  3. Basic Usage
  4. Internal Route (String Path)
  5. Internal Route (Object with Name)
  6. Internal Route (Object with Path and Query)
  7. External Link
  8. Props
  9. TypeScript Type Safety
  10. Examples
  11. Navigation Menu
  12. External Links with Security
  13. Disabled State
  14. Danger Link
  15. Replace Navigation
  16. Accessibility
  17. ARIA Attributes
  18. Security
  19. Related Components

@fiscozen/link

Flexible link component supporting internal routing (vue-router) and external navigation. Automatically renders as router-link for internal routes, anchor tag for external URLs, or non-interactive span when disabled.

Features

  • Internal Routing: Uses vue-router for SPA navigation with RouteLocationRaw support (string or object)
  • External Navigation: Supports external URLs with anchor tags
  • Disabled State: Renders as non-interactive span with disabled styling
  • Multiple Variants: Default and danger types
  • Text Styles: Default (underline on hover) or always underlined
  • Size Options: sm, md
  • TypeScript Type Safety: Discriminated union types enforce correct prop combinations
  • Full Accessibility: ARIA support and keyboard navigation
  • Security: Automatic rel="noopener noreferrer" for external links with target="_blank"

Installation

npm install @fiscozen/link

Basic Usage

Internal Route (String Path)

<script setup lang="ts">
import { FzLink } from '@fiscozen/link'
</script>

<template>
  <FzLink to="/dashboard" size="md">Go to Dashboard</FzLink>
</template>

Internal Route (Object with Name)

<template>
  <FzLink :to="{ name: 'user', params: { id: 123 }}">
    User Profile
  </FzLink>
</template>

Internal Route (Object with Path and Query)

<template>
  <FzLink :to="{ path: '/search', query: { q: 'vue' }}">
    Search Results
  </FzLink>
</template>
<template>
  <FzLink to="https://example.com" external target="_blank">
    External Site
  </FzLink>
</template>

Props

PropTypeDefaultDescription
toRouteLocationRaw | string-Destination route or URL. Type depends on external prop: Internal (external=false or undefined): Accepts vue-router RouteLocationRaw (string path or object with name/path, params, query, etc.). External (external=true): Must be a string URL.
type'default' | 'danger''default'Visual variant indicating link purpose. Affects color scheme.
linkStyle'default' | 'underline''default'Text decoration style. 'default' shows underline on hover, 'underline' always shows underline.
size'sm' | 'md''md'Text size affecting font size and line height.
disabledbooleanfalseDisables the link, rendering as non-interactive span with disabled styling.
targetstring-Target attribute for anchor tag (e.g., '_blank', '_self'). Can be used with both internal (router-link) and external links.
externalbooleanfalseWhen true, renders as anchor tag with href instead of router-link. Use for external URLs or when router navigation is not desired.
replacebooleanfalseUses router.replace instead of router.push for navigation. Only applies to internal routes (when external is false).

TypeScript Type Safety

The component uses discriminated union types to enforce correct prop combinations:

  • Internal links (external=false or undefined):

    • to accepts RouteLocationRaw (string path or object with name/path, params, query, etc.)
    • replace can be used
    • target can be used (opens internal route in new tab/window)
  • External links (external=true):

    • to must be a string URL
    • target can be used
    • replace cannot be used (not applicable for external links)

TypeScript will show errors if you try to use incompatible prop combinations.

Examples

Navigation Menu

<template>
  <nav>
    <FzLink to="/dashboard" size="md">Dashboard</FzLink>
    <FzLink to="/settings" size="md">Settings</FzLink>
    <FzLink :to="{ name: 'profile', params: { id: userId }}" size="md">
      Profile
    </FzLink>
  </nav>
</template>
<template>
  <FzLink to="https://example.com" external target="_blank">
    Visit Example Site
  </FzLink>
</template>

The component automatically adds rel="noopener noreferrer" for security when target="_blank" is used.

Disabled State

<template>
  <FzLink to="/premium" disabled>
    Premium Feature (Requires Upgrade)
  </FzLink>
</template>
<template>
  <FzLink to="/delete-account" type="danger" size="md">
    Delete Account
  </FzLink>
</template>

Replace Navigation

<template>
  <FzLink to="/redirect" replace>
    Redirect Without History
  </FzLink>
</template>

Accessibility

FzLink is fully accessible and meets WCAG 2.1 AA standards:

  • Keyboard Navigation: All links are keyboard accessible (Tab, Enter)
  • Screen Readers: Proper ARIA attributes for disabled state
  • Focus Indicators: Visible focus outline with proper contrast
  • Semantic HTML: Uses router-link for internal routes, anchor for external
  • Disabled State: Renders as span with aria-disabled, role="link", and aria-label

ARIA Attributes

  • aria-disabled: Set to "true" when link is disabled (string value for Vue 3 compatibility)
  • role: Set to "link" for disabled span to maintain semantic meaning
  • aria-label: Provides accessible label for disabled links
  • rel: Automatically adds "noopener noreferrer" for external links with target="_blank"

Security

External links with target="_blank" automatically include rel="noopener noreferrer" to:

  • Prevent security vulnerabilities (window.opener access)
  • Improve privacy (no referrer information sent)
  • FzNavlink: Navigation link with active state support
  • FzButton: Button component for actions
  • FzRouterNavlink: Router-aware navigation link

版本与发布记录

@fiscozen/link 共发布 8 个版本,首次发布于 2024/06/19;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.1latest2026/04/306 个月前
1.0.02026/02/139 个月前
1.0.0-next.0next2025/11/111 年前
0.1.42025/04/011.6 年前
0.1.32024/10/142 年前
0.1.22024/09/092 年前

关于 @fiscozen/link 的常见问题

@fiscozen/link 是什么?

Design System Link component

如何安装 @fiscozen/link?

在项目目录运行 npm install @fiscozen/link,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:tailwindcss(^3.4.1)、vue(^3.4.13)、vue-router(^4.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fiscozen/link 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fiscozen__link 是否存在。

@fiscozen/link 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fiscozen/link 可以商用吗?

@fiscozen/link 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fiscozen/link 的下载量有多少?

根据 npm 官方下载统计,@fiscozen/link 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,338 次,日均约 78 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fiscozen/link 还在维护吗?

最新版本 1.0.1 发布于 2026/04/30(6 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 2 个;首次发布于 2024/06/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。