← All @molecule/* packages · App templates

@molecule/app-safe-link-react

Feature · safe-link · App (browser) · v1.0.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>
}

Reference

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.

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

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 react react-router
npm install -D @types/react

API

Functions

SafeLink(props)

<SafeLink> renders a react-router 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
}: Omit<LinkProps & RefAttributes<HTMLAnchorElement>, 'to'> & {
  to: string
  children?: ReactNode
}): JSX.Element

Injection Notes

Requirements

Peer dependencies:

  • react ^18.0.0 || ^19.0.0
  • react-router ^7.0.0 || ^8.0.0

Runtime Dependencies

  • react

  • react-router

  • Must render inside a react-router <Router> / RouterProvideruseLocation() throws otherwise. Peer-depends on react-router-dom v6/v7; 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").