Skip to content

docs: Update TanStack Router guide #8632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions packages/dev/docs/pages/react-aria/routing.mdx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we wanna perhaps list the version (aka this latest release) that is needed for this to work? I know sometimes people get confused since they don't know when a new feature/fix got added/updated

Original file line number Diff line number Diff line change
Expand Up @@ -268,29 +268,17 @@ export default function App() {
}
```

### TanStack Router
## TanStack Router

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.
To use [TanStack Router](https://tanstack.com/router) with React Aria, 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.

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

declare module 'react-aria-components' {
interface RouterConfig {
href: ToOptions;
routerOptions: Omit<NavigateOptions, keyof ToOptions>;
}
}

function RootRoute() {
let router = useRouter();
return (
<RouterProvider
navigate={(href, opts) => router.navigate({...href, ...opts})}
useHref={href => router.buildLocation(href).href}>
{/* ...*/}
</RouterProvider>
);
}
export const Link = createLink(ReactAriaLink);
export const MenuItemLink = createLink(MenuItem);
```

In you app, use these components instead of importing directly from `react-aria-components`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In you app, use these components instead of importing directly from `react-aria-components`.
In your app, use these components instead of importing directly from `react-aria-components`.

33 changes: 9 additions & 24 deletions packages/dev/docs/pages/react-spectrum/routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -270,32 +270,17 @@ export default function App() {
}
```

### TanStack Router
## TanStack Router

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.
To use [TanStack Router](https://tanstack.com/router) with React Spectrum, 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.

```tsx
import {useRouter, type NavigateOptions, type ToOptions} from '@tanstack/react-router';
import {Provider, defaultTheme} from '@adobe/react-spectrum';

declare module '@adobe/react-spectrum' {
interface RouterConfig {
href: ToOptions['to'];
routerOptions: Omit<NavigateOptions, keyof ToOptions>;
}
}
// src/Link.tsx
import {createLink} from '@tanstack/react-router';
import {Link as SpectrumLink, Item} from '@adobe/react-spectrum';

function RootRoute() {
let router = useRouter();
return (
<Provider
theme={defaultTheme}
router={{
navigate: (to, options) => router.navigate({to, ...options}),
useHref: to => router.buildLocation({to}).href
}}>
{/* ...*/}
</Provider>
);
}
export const Link = createLink(SpectrumLink);
export const ItemLink = createLink(Item);
```

In you app, use these components instead of importing directly from `@adobe/react-spectrum`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In you app, use these components instead of importing directly from `@adobe/react-spectrum`.
In your app, use these components instead of importing directly from `@adobe/react-spectrum`.