A link allows a user to navigate to another page or resource within a web page or application.
Client side routing
By default, links with an href are handled by the browser as regular page navigations. To integrate with a client side router, use the render prop to delegate to your router's link component. This supports features like prefetching on hover and avoids full page reloads.
import {Link} from 'react-aria-components/Link';
import NextLink from 'next/link';
<Link href="/about" render={props => <NextLink {...props} />}>
About
</Link>
See the customization guide for more details on the render prop.
Events
Links without an href will be rendered as a <span role="link"> instead of an <a>. Use the onPress event to handle user interaction.
import {Link} from './Link';
<Link onPress={() => alert('Pressed link')}>Link</Link>
API
| Name | Type | |
|---|---|---|
isDisabled | boolean | |
Whether the link is disabled. | ||
children | ChildrenOrFunction | |
The children of the component. A function may be provided to alter the children based on component state. | ||
onPress | | |
Handler that is called when the press is released over the target. | ||
onPressStart | | |
Handler that is called when a press interaction starts. | ||
onPressEnd | | |
Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. | ||
onPressChange | | |
Handler that is called when the press state changes. | ||
onPressUp | | |
Handler that is called when a press is released over the target, regardless of whether it started on the target or not. | ||
onClick | | |
Not recommended – use | ||
onFocus | | |
Handler that is called when the element receives focus. | ||
onBlur | | |
Handler that is called when the element loses focus. | ||
onFocusChange | | |
Handler that is called when the element's focus status changes. | ||
onKeyDown | | |
Handler that is called when a key is pressed. | ||
onKeyUp | | |
Handler that is called when a key is released. | ||
onHoverStart | | |
Handler that is called when a hover interaction starts. | ||
onHoverEnd | | |
Handler that is called when a hover interaction ends. | ||
onHoverChange | | |
Handler that is called when the hover state changes. | ||
href | Href | |
A URL to link to. See MDN. | ||
hrefLang | string | |
Hints at the human language of the linked URL. SeeMDN. | ||
target | HTMLAttributeAnchorTarget | |
The target window for the link. See MDN. | ||
rel | string | |
The relationship between the linked resource and the current page. See MDN. | ||
download | boolean | string | |
Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN. | ||
ping | string | |
A space-separated list of URLs to ping when the link is followed. See MDN. | ||
referrerPolicy | HTMLAttributeReferrerPolicy | |
How much of the referrer to send when following the link. See MDN. | ||
routerOptions | RouterOptions | |
Options for the configured client side router. | ||
style | StyleOrFunction | |
The inline style for the element. A function may be provided to compute the style based on component state. | ||
className | ClassNameOrFunction | |
The CSS className for the element. A function may be provided to compute the class based on component state. | ||
autoFocus | boolean | |
Whether the element should receive focus on render. | ||
id | string | |
The element's unique identifier. See MDN. | ||
aria-current | boolean
| 'true'
| 'false'
| 'page'
| 'step'
| 'location'
| 'date'
| 'time' | |
Indicates whether this element represents the current item within a container or set of related elements. | ||
aria-label | string | |
Defines a string value that labels the current element. | ||
aria-labelledby | string | |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
slot | string | null | |
A slot name for the component. Slots allow the component to receive props from a parent
component. An explicit | ||
render | | |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Note: You can check if Requirements:
| ||
Default className: react-aria-Link
| Render Prop | CSS Selector |
|---|---|
isCurrent | CSS Selector: [data-current]
|
| Whether the link is the current item within a list. | |
isHovered | CSS Selector: [data-hovered]
|
| Whether the link is currently hovered with a mouse. | |
isPressed | CSS Selector: [data-pressed]
|
| Whether the link is currently in a pressed state. | |
isFocused | CSS Selector: [data-focused]
|
| Whether the link is focused, either via a mouse or keyboard. | |
isFocusVisible | CSS Selector: [data-focus-visible]
|
| Whether the link is keyboard focused. | |
isDisabled | CSS Selector: [data-disabled]
|
| Whether the link is disabled. | |