Skip to content

Commit 2d9262c

Browse files
authored
docs: Update TanStack Router guide (#8632)
1 parent da09a6d commit 2d9262c

File tree

2 files changed

+18
-45
lines changed

2 files changed

+18
-45
lines changed

packages/dev/docs/pages/react-aria/routing.mdx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,29 +268,17 @@ export default function App() {
268268
}
269269
```
270270

271-
### TanStack Router
271+
## TanStack Router
272272

273-
To use [TanStack Router](https://tanstack.com/router) with React Aria, render React Aria's `RouterProvider` inside your root route. Use `router.navigate` in the `navigate` prop, and `router.buildLocation` in the `useHref` prop. You can also configure TypeScript to get autocomplete for the `href` prop by declaring the `RouterConfig` type using the types provided by TanStack Router.
273+
To use [TanStack Router](https://tanstack.com/router) with React Aria Components v1.11.0 or later, use the [createLink](https://tanstack.com/router/latest/docs/framework/react/guide/custom-link) function to wrap each React Aria component as a link. `RouterProvider` is not needed.
274274

275275
```tsx
276-
import {useRouter, type NavigateOptions, type ToOptions} from '@tanstack/react-router';
277-
import {RouterProvider} from 'react-aria-components';
276+
// src/Link.tsx
277+
import {createLink} from '@tanstack/react-router';
278+
import {Link as ReactAriaLink, MenuItem} from 'react-aria-components';
278279

279-
declare module 'react-aria-components' {
280-
interface RouterConfig {
281-
href: ToOptions;
282-
routerOptions: Omit<NavigateOptions, keyof ToOptions>;
283-
}
284-
}
285-
286-
function RootRoute() {
287-
let router = useRouter();
288-
return (
289-
<RouterProvider
290-
navigate={(href, opts) => router.navigate({...href, ...opts})}
291-
useHref={href => router.buildLocation(href).href}>
292-
{/* ...*/}
293-
</RouterProvider>
294-
);
295-
}
280+
export const Link = createLink(ReactAriaLink);
281+
export const MenuItemLink = createLink(MenuItem);
296282
```
283+
284+
In your app, use these components instead of importing directly from `react-aria-components`.

packages/dev/docs/pages/react-spectrum/routing.mdx

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -270,32 +270,17 @@ export default function App() {
270270
}
271271
```
272272

273-
### TanStack Router
273+
## TanStack Router
274274

275-
To use [TanStack Router](https://tanstack.com/router) with React Spectrum, render React Spectrum's `Provider` inside your root route. Use `router.navigate` in the `navigate` prop, and `router.buildLocation` in the `useHref` prop. You can also configure TypeScript to get autocomplete for the `href` prop by declaring the `RouterConfig` type using the types provided by TanStack Router.
275+
To use [TanStack Router](https://tanstack.com/router) with React Spectrum v3.43.0 or later, use the [createLink](https://tanstack.com/router/latest/docs/framework/react/guide/custom-link) function to wrap each React Spectrum component as a link. `RouterProvider` is not needed.
276276

277277
```tsx
278-
import {useRouter, type NavigateOptions, type ToOptions} from '@tanstack/react-router';
279-
import {Provider, defaultTheme} from '@adobe/react-spectrum';
280-
281-
declare module '@adobe/react-spectrum' {
282-
interface RouterConfig {
283-
href: ToOptions['to'];
284-
routerOptions: Omit<NavigateOptions, keyof ToOptions>;
285-
}
286-
}
278+
// src/Link.tsx
279+
import {createLink} from '@tanstack/react-router';
280+
import {Link as SpectrumLink, Item} from '@adobe/react-spectrum';
287281

288-
function RootRoute() {
289-
let router = useRouter();
290-
return (
291-
<Provider
292-
theme={defaultTheme}
293-
router={{
294-
navigate: (to, options) => router.navigate({to, ...options}),
295-
useHref: to => router.buildLocation({to}).href
296-
}}>
297-
{/* ...*/}
298-
</Provider>
299-
);
300-
}
282+
export const Link = createLink(SpectrumLink);
283+
export const ItemLink = createLink(Item);
301284
```
285+
286+
In your app, use these components instead of importing directly from `@adobe/react-spectrum`.

0 commit comments

Comments
 (0)