You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -127,7 +127,7 @@ import {Breadcrumbs, Breadcrumb, Link} from 'react-aria-components';
127
127
Breadcrumbs provide a list of links to parent pages of the current page in hierarchical order.
128
128
`Breadcrumbs` helps implement these in an accessible way.
129
129
130
-
***Flexible** – Support for navigation links, JavaScript handled links, or custom element types (e.g. router links).
130
+
***Flexible** – Support for HTML navigation links, JavaScript handled links, and client side routing.
131
131
***Accessible** – Implemented as an ordered list of links. The last link is automatically marked as the current page using `aria-current`.
132
132
***Styleable** – Hover, press, and keyboard focus states are provided for easy styling. These states only apply when interacting with an appropriate input device, unlike CSS pseudo classes.
133
133
@@ -207,19 +207,40 @@ function Example() {
207
207
}
208
208
```
209
209
210
-
##Router links
210
+
### Client side routing
211
211
212
-
The `<Link>` component can wrap a custom link element provided by a router like [React Router](https://reactrouter.com/en/main).
212
+
The `<Link>` component works with frameworks and client side routers like [Next.js](https://nextjs.org/) and [React Router](https://reactrouter.com/en/main). As with other React Aria components that support links, this works via the `RouterProvider` component at the root of your app. Any `<Link>` within a `<RouterProvider>` will trigger the provided `navigate` function when pressed, and prevent the browser default navigation behavior.
213
+
214
+
This example uses React Router but the structure is applicable for any router.
Note that external links to different origins will not trigger client side routing.
243
+
223
244
## Separator icons
224
245
225
246
The above examples use the CSS `:after` pseudo class to add separators between each item. These may also be DOM elements instead, e.g. SVG icons. Be sure that they have `aria-hidden="true"` so they are hidden from assistive technologies.
@@ -229,7 +250,7 @@ import ChevronIcon from '@spectrum-icons/workflow/ChevronDoubleRight';
229
250
230
251
<Breadcrumbs>
231
252
<BreadcrumbclassName="my-item">
232
-
<Link><ahref="/">Home</a></Link>
253
+
<Linkhref="/">Home</Link>
233
254
<ChevronIconsize="S" />
234
255
</Breadcrumb>
235
256
<Breadcrumb><Link>React Aria</Link></Breadcrumb>
@@ -256,8 +277,8 @@ When breadcrumbs are used as a main navigation element for a page, they can be p
@@ -109,7 +107,7 @@ element with an `href` attribute. However, if the link does not have an href, an
109
107
handled client side with JavaScript instead, it will not be exposed to assistive technology properly.
110
108
`Link` helps achieve accessible links with either native HTML elements or custom element types.
111
109
112
-
***Flexible** – Support for navigation links, JavaScript handled links, or custom element types (e.g. router links). Disabled links are also supported.
110
+
***Flexible** – Support for HTML navigation links, JavaScript handled links, and client side routing. Disabled links are also supported.
113
111
***Accessible** – Implemented as a custom ARIA link when handled via JavaScript, and otherwise as a native HTML link.
114
112
***Styleable** – Hover, press, and keyboard focus states are provided for easy styling. These states only apply when interacting with an appropriate input device, unlike CSS pseudo classes.
115
113
@@ -122,23 +120,42 @@ keyboard users may activate links using the <Keyboard>Enter</Keyboard> key.
122
120
If a visual label is not provided (e.g. an icon or image only link), then an `aria-label` or
123
121
`aria-labelledby` prop must be passed to identify the link to assistive technology.
124
122
125
-
## Content
123
+
## Events
124
+
125
+
### Client side routing
126
126
127
-
### Routerlinks
127
+
The `<Link>` component works with frameworks and client side routers like [Next.js](https://nextjs.org/) and [React Router](https://reactrouter.com/en/main). As with other React Aria components that support links, this works via the `RouterProvider` component at the root of your app. Any `<Link>` within a `<RouterProvider>` will trigger the provided `navigate` function when pressed, and prevent the browser default navigation behavior.
128
128
129
-
The `<Link>` component can wrap a custom link element provided by a router like [React Router](https://reactrouter.com/en/main).
129
+
This example uses React Router but the structure is applicable for any router.
With this setup in the root of your app, any link within it will automatically trigger client side routing.
146
+
147
+
```tsx
148
+
<App>
149
+
{/* ... */}
150
+
<Linkhref="/foo">Foo</Link>
151
+
</App>
152
+
```
153
+
154
+
Note that external links to different origins will not trigger client side routing.
155
+
156
+
### JavaScript handled links
140
157
141
-
When the content is plain text, a `<Link>`is rendered as a `<span>`but exposed to assistive technologies as a link. Events will need to be handled in JavaScript with the `onPress` prop.
158
+
When a `<Link`> does not have an `href` prop, it is rendered as a `<span role="link">`instead of an `<a>`. Events will need to be handled in JavaScript with the `onPress` prop.
142
159
143
160
Note: this will not behave like a native link. Browser features like context menus and open in new tab will not apply.
144
161
@@ -176,7 +193,7 @@ link elements as well as client handled links. Native navigation will be disable
176
193
event will not be fired. The link will be exposed as disabled to assistive technology with ARIA.
0 commit comments