Skip to content

Commit c714b8d

Browse files
committed
docs: add TanStack Start docs
1 parent bd7e28f commit c714b8d

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

docs/TanStackStart.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
layout: default
3+
title: "React-admin With TanStack Start"
4+
---
5+
6+
# React-admin With TanStack Start
7+
8+
React-admin supports [TanStack Router](https://tanstack.com/router/latest) as an alternative to react-router. This allows you to use react-admin in a TanStack Start application.
9+
10+
## Setting Up TanStack Start
11+
12+
Let's start by creating a new TanStack Start project. Run the following command:
13+
14+
```bash
15+
npm create @tanstack/start@latest
16+
```
17+
18+
This script will ask you for more details about your project. Follow the prompts, then move into the project directory.
19+
20+
## Setting Up React-Admin In TanStack Start
21+
22+
Add the `react-admin` and `ra-router-tanstack` packages, as well as a data provider package. In this example, we'll use `ra-data-json-server` to connect to a test API provided by [JSONPlaceholder](https://jsonplaceholder.typicode.com).
23+
24+
```bash
25+
cd tanstack-start-admin
26+
npm install react-admin ra-router-tanstack ra-data-json-server
27+
# or
28+
yarn add react-admin ra-router-tanstack ra-data-json-server
29+
```
30+
31+
## Adding React-Admin In A Route
32+
33+
Create a new route at `/admin` and render react-admin there. TanStack Start uses file-based routing, so create `src/routes/admin.tsx` (or the equivalent routes directory in your template) with the following content:
34+
35+
```tsx
36+
// in src/routes/admin.tsx
37+
import { createFileRoute } from '@tanstack/react-router';
38+
import { Admin, Resource, ListGuesser } from 'react-admin';
39+
import jsonServerProvider from 'ra-data-json-server';
40+
import { tanStackRouterProvider } from 'ra-router-tanstack';
41+
42+
const dataProvider = jsonServerProvider('https://jsonplaceholder.typicode.com');
43+
44+
export const Route = createFileRoute('/admin')({
45+
component: AdminRoute,
46+
});
47+
48+
function AdminRoute() {
49+
return (
50+
<Admin
51+
dataProvider={dataProvider}
52+
routerProvider={tanStackRouterProvider}
53+
basename="/admin"
54+
>
55+
<Resource name="posts" list={ListGuesser} />
56+
<Resource name="comments" list={ListGuesser} />
57+
</Admin>
58+
);
59+
}
60+
61+
```
62+
63+
**Tip**: Don't forget to set the `<Admin basename>` prop, so that react-admin generates links relative to the `/admin` subpath.
64+
65+
You can now start the app in `development` mode with `npm run dev`. The admin should render at `/admin` on your dev server.
66+
67+
## Next Steps
68+
69+
For standalone vs embedded setups, see the [TanStack Router Integration](./TanStackRouter.md).

docs/navigation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<li {% if page.path == 'Remix.md' %} class="active" {% endif %}><a class="nav-link" href="./Remix.html">Remix</a></li>
1717
<li {% if page.path == 'ReactRouterFramework.md' %} class="active" {% endif %}><a class="nav-link" href="./ReactRouterFramework.html">React Router Framework</a></li>
1818
<li {% if page.path == 'Deploy.md' %} class="active beginner" {% endif %}><a class="nav-link" href="./Deploy.html">Deployment</a></li>
19+
<li {% if page.path == 'TanStackStart.md' %} class="active" {% endif %}><a class="nav-link" href="./TanStackStart.html">TanStack Start</a></li>
1920
</ul>
2021

2122
<ul><div>Guides & Concepts</div>

0 commit comments

Comments
 (0)