Link
A router-aware link that moves between theme pages without a full page reload.
Use Link for every link to another page of your theme. The customer moves between pages without a full reload, and the target can be preloaded.
Framework: TanStack Start
This page is written for TanStack Start, the default and currently supported framework. See what depends on the framework.
Example
import { Link } from '@salla.sa/twilight-theme-engine/common';
export function BrandLink({ id, name }: { id: number; name: string }) {
return (
<Link to={`/brands/${id}`} preload="intent" className="brand">
{name}
</Link>
);
}API
const Link: ForwardRefExoticComponent<LinkProps & RefAttributes<HTMLAnchorElement>>;| Prop | Type | Description |
|---|---|---|
to? | string | Destination path. Falls back to href, then "/". |
href? | string | Alternative to to. |
preload? | "intent" | "render" | false | When to preload the target: on hover or focus, when rendered, or never. |
replace? | boolean | Replace the current history entry instead of adding one. |
className? | string | Class name. |
style? | CSSProperties | Inline styles. |
title? | string | Title attribute. |
target? | string | Anchor target. |
rel? | string | Anchor rel. |
onClick? | MouseEventHandler<HTMLAnchorElement> | Click handler. |
aria-label? | string | Accessible label. |
itemProp? | string | Microdata attribute. |
children? | ReactNode | Link content. |
Gotchas
- Use
Linkfor pages inside the theme. For external addresses, use a plain<a>. - Only the props above are typed. Other anchor attributes are not part of the public type.
Linkadds adata-spa-linkattribute, and it needs the Twilight provider above it (your root route already has it).- A plain
<a href>inside your theme still works, but it reloads the whole page. The built-inProductCarduses plain anchors for product links.
Next
- Routes and pages shows which paths exist.
Imagefor pictures.- Layout and components