Components / Foundations
LinkBase
The native <a> for Cynosure, and the only module allowed to render one. It is a foundation: it adds safe link behaviour and no styling.
Who uses itLink to "Who uses it"
Link and Card (when it navigates), and any composite that navigates.
When to use it directlyLink to "When to use it directly"
Only when building a new composite that navigates and needs a native anchor.
Use a component instead when you want a link in content: Link. For an action that does not navigate, use Button.
UsageLink to "Usage"
tsx
import { LinkBase } from "@arshad-shah/cynosure";
<LinkBase className="my-link" href="/docs">Docs</LinkBase>
<LinkBase href="https://example.com" target="_blank">Example</LinkBase>
<LinkBase href="javascript:alert(1)">Dropped</LinkBase> // renders <a> with no hrefPropsLink to "Props"
It accepts every native anchor attribute.
GuaranteesLink to "Guarantees"
- New tabs: with
target="_blank",relgetsnoopener noreferreradded after anyrelyou pass. - Safe schemes only:
hrefis checked bysafeHref(internal to LinkBase). Relative, hash and query URLs, andhttp,https,mailtoandtelare linked. Anything else, includingjavascript:, is dropped and the anchor gets nohref. - Parsed like a browser:
safeHrefstrips tab and newline characters anywhere and leading control characters before checking, so obfuscatedjavascript:URLs cannot slip through. An unparseable absolute URL is dropped. - The ref reaches the native
<a>.
RelatedLink to "Related"
These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.