@molecule/app-safe-link-react

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

SafeLink React 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-react

npm · Source on GitHub

How it works

@molecule/app-safe-link-react 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-react'

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

Works with: @molecule/app-react

Reference

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

Note: "safe" refers to dead-link-probe safety only — this adds NO security behavior (no rel="noopener", no URL allowlisting). All other Link props 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-react'

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

Type

feature

Installation

npm install @molecule/app-safe-link-react @molecule/app-react react
npm install -D @types/react

API

Types

SafeLinkProps

Props accepted by SafeLink: LinkProps from @molecule/app-react/link, with to a string path only.

type SafeLinkProps = Omit<LinkProps, 'to'> & {
  /**
   * Destination: a string path only (`/settings`, `/blog/`). A `#top` fragment is
   * appended when it matches the current path.
   */
  to: string
  /** The link's content. */
  children?: ReactNode
}

Functions

SafeLink(props)

<SafeLink> renders a Link from @molecule/app-react/link, 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.

function SafeLink({ to, children, ...rest }: SafeLinkProps): JSX.Element

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-react ^4.12.0 || ^5.0.0
  • react ^18.0.0 || ^19.0.0

Runtime Dependencies

  • @molecule/app-react

  • react

  • Must render inside the app's router (RouterProvider) — useLocation() throws otherwise. Imports its Link and useLocation from @molecule/app-react / @molecule/app-react/link, so it works under every routing bond and peer-depends on @molecule/app-react.

  • 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").