@molecule/app-safe-link-vue

Feature · safe-link · App (browser) · v1.1.2 · Apache-2.0

SafeLink Vue router wrapper that appends a #top fragment when target matches current path. Avoids dead-link probes that return no URL/DOM mutation on same-path clicks.

npm install @molecule/app-safe-link-vue

npm · Source on GitHub

How it works

@molecule/app-safe-link-vue is a ready-made safe-link feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { createApp, defineComponent, h } from 'vue'
import { SafeLink } from '@molecule/app-safe-link-vue'

const NavItem = defineComponent({
  setup() {
    return () => h(SafeLink, { to: '/dashboard' }, () => 'Dashboard')
  },
})

createApp(NavItem).mount('#app')

Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue

Reference

@molecule/app-safe-link-vue — a <Link> wrapper that appends a #top fragment when the destination matches the current path, so a same-path click still produces an observable URL change. Useful for nav primitives exercised by behavioural verifiers / e2e probes. Vue counterpart of @molecule/app-safe-link-react: the same props (React names) and the same DOM for the same input.

Note: "safe" refers to dead-link-probe safety only — this adds NO security behavior (no rel="noopener", no URL allowlisting). All other Link attributes pass through unchanged.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { createApp, defineComponent, h } from 'vue'
import { SafeLink } from '@molecule/app-safe-link-vue'

const NavItem = defineComponent({
  setup() {
    return () => h(SafeLink, { to: '/dashboard' }, () => 'Dashboard')
  },
})

createApp(NavItem).mount('#app')

Type

feature

Installation

npm install @molecule/app-safe-link-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

API

Interfaces

SafeLinkProps

Props accepted by the SafeLink component.

interface SafeLinkProps {
  /**
   * Destination: a string path only (`/settings`, `/blog/`), as with react-router's
   * `<Link to>` (no partial-Path objects). Rendered as the anchor's `href`, with a
   * `#top` fragment appended when it matches the current path.
   */
  to: string
  /**
   * Replace the current history entry instead of pushing one. When omitted, a
   * link to the location already shown replaces it and any other link pushes,
   * as with react-router's `<Link>`.
   */
  replace?: boolean
  /** State stored with the new history entry (read back with `useLocation()`). */
  state?: unknown
  /** Extra classes on the anchor. */
  className?: string
  /** The link's content. */
  children?: VNodeChild
  /** The anchor's click listener; it runs before the in-app navigation, like react-router's `<Link onClick>`. */
  onClick?: (event: MouseEvent) => unknown
}

Constants

<SafeLink> renders the binding's Link (react-router <Link>'s click rules), but if its destination matches the current path it appends a #top fragment so clicking still produces an observable URL change.

Avoids "dead-link" probes that return no URL/DOM mutation when a same-path link is clicked — useful for nav primitives that get exercised by behavioural verifiers / e2e probes.

Every other attribute (class via className, id, target, rel, aria-*, data-*, onClick) goes on the anchor, as with react-router's <Link>.

const SafeLink: DefineComponent<
  ExtractPropTypes<{
    to: { type: StringConstructor; required: true }
    replace: { type: BooleanConstructor; default: undefined }
    state: null
    className: StringConstructor
  }>,
  () => VNode,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      to: { type: StringConstructor; required: true }
      replace: { type: BooleanConstructor; default: undefined }
      state: null
      className: StringConstructor
    }>
  > &
    Readonly<{}>,
  { replace: boolean },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — The link's props (see SafeLinkProps); other attributes go on the anchor.
  • ctx — The setup context: the default slot is the link's content.

Returns: The render function of the anchor.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.11.0 || ^4.0.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui

  • @molecule/app-ui-vue

  • @molecule/app-vue

  • vue

  • Must render inside the molecule router (createRouterPlugin / moleculePlugin with a router) — useLocation() throws otherwise. The click rules are the binding Link's (followRouterLink from @molecule/app-routing), react-router <Link>'s contract. Do not use in apps on a different router.

  • to accepts a string path only (no partial-Path objects).

  • Use the NAMED import (import { SafeLink } from …); the package barrel does not re-export the file's default export.

  • Internal routes only — for external URLs use a plain <a> (with rel="noopener noreferrer" when target="_blank").