@molecule/app-safe-link-svelte

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

SafeLink Svelte 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-svelte

npm · Source on GitHub

How it works

@molecule/app-safe-link-svelte 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.

<script lang="ts">
  import { SafeLink } from '@molecule/app-safe-link-svelte'
</script>

<nav>
  <SafeLink to="/dashboard">Dashboard</SafeLink>
</nav>

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

Reference

@molecule/app-safe-link-svelte — 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. Svelte 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

<script lang="ts">
  import { SafeLink } from '@molecule/app-safe-link-svelte'
</script>

<nav>
  <SafeLink to="/dashboard">Dashboard</SafeLink>
</nav>

Type

feature

Installation

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

API

Interfaces

SafeLinkProps

Props of the Svelte SafeLink component.

interface SafeLinkProps extends Omit<
  HTMLAnchorAttributes,
  'href' | 'children' | 'onclick' | 'class'
> {
  /**
   * 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 anchor's click listener; it runs before the in-app navigation, like
   * react-router's `<Link onClick>`. Svelte's own `onclick` attribute stays
   * available through the rest props.
   */
  onClick?: (event: MouseEvent & { currentTarget: EventTarget & HTMLAnchorElement }) => void
  /** The link's content. */
  children?: Snippet
}

Constants

const SafeLink: LegacyComponentType

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-svelte ^3.11.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-svelte ^1.1.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-svelte

  • @molecule/app-ui

  • @molecule/app-ui-svelte

  • svelte

  • Must render inside the molecule context (setMoleculeContext 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 component file's default export.

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