@molecule/app-safe-link-solid

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

SafeLink Solid 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-solid

npm · Source on GitHub

How it works

@molecule/app-safe-link-solid 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 { SafeLink } from '@molecule/app-safe-link-solid'

export function NavItem() {
  return <SafeLink to="/dashboard">Dashboard</SafeLink>
}

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

Reference

@molecule/app-safe-link-solid — 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. Solid 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 { SafeLink } from '@molecule/app-safe-link-solid'

export function NavItem() {
  return <SafeLink to="/dashboard">Dashboard</SafeLink>
}

Type

feature

Installation

npm install @molecule/app-safe-link-solid @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js

API

Interfaces

SafeLinkProps

Props accepted by the SafeLink component.

interface SafeLinkProps extends Omit<
  JSX.AnchorHTMLAttributes<HTMLAnchorElement>,
  'href' | 'onClick' | 'children'
> {
  /**
   * 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?: JSX.Element
  /** The anchor's click listener; it runs before the in-app navigation, like react-router's `<Link onClick>`. */
  onClick?: JSX.EventHandlerUnion<HTMLAnchorElement, MouseEvent>
}

Functions

SafeLink(props)

<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>.

function SafeLink(props: SafeLinkProps): JSX.Element
  • props — The link's SafeLinkProps; other attributes go on the anchor.

Returns: The anchor.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-solid ^3.11.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-solid ^1.1.0
  • solid-js ^1.8.0

Runtime Dependencies

  • @molecule/app-solid

  • @molecule/app-ui

  • @molecule/app-ui-solid

  • solid-js

  • Must render inside a MoleculeProvider whose config has 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").