Create a custom anchor-based link while retaining router navigation.
Custom navigation UI
TanStack · Hook
useLinkProps creates React anchor props from TanStack Router link options and ordinary anchor attributes. Apply the returned props to an anchor to build a navigational link.
useLinkProps converts route-link options plus ordinary anchor attributes into a props object for a native anchor. Applying the returned object to an anchor creates a link that can navigate while incorporating pathname, search parameters, hash, and location state.
useLinkProps(options: UseLinkPropsOptions): React.AnchorHTMLAttributes<HTMLAnchorElement>| Name | Type | Description |
|---|---|---|
options | UseLinkPropsOptions | An object combining ActiveLinkOptions with React anchor attributes; it supplies navigation details and any additional anchor props. |
A React.AnchorHTMLAttributes<HTMLAnchorElement> object that can be applied to an anchor element for navigation.
import { useLinkProps } from '@tanstack/react-router'
export function ProfileLink() {
const linkProps = useLinkProps({
to: '/profile',
children: 'Profile',
className: 'profile-link',
})
return <a {...linkProps} />
}Builds anchor attributes from route options and applies them to a native anchor for client-side navigation.
Custom navigation UI
Reusable link wrappers
Rich route targets
It accepts an options object and returns React anchor attributes. Those attributes can be spread onto an anchor to create a link capable of navigating to a new location.
Follow-up: How does it differ from rendering Link? useLinkProps gives you the computed props, while Link is the component-level abstraction that renders the anchor.
The options type combines ActiveLinkOptions with React.AnchorHTMLAttributes<HTMLAnchorElement>. This lets route-navigation options and normal anchor attributes be supplied together.
Follow-up: Why is that combination useful? It allows a custom anchor component to preserve native HTML attributes while using TanStack Router navigation behavior.
The generated link can represent changes to the pathname, search parameters, hash, and location state. The returned object is intended to be applied directly to an anchor element.
Follow-up: What element should consume the result? A React anchor element, because the documented return type is React.AnchorHTMLAttributes<HTMLAnchorElement>.
ActiveLinkOptionsLinkLinkPropsuseNavigate