Skip to content

Conversation

@fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Jan 2, 2026

Problem

React-admin is tied to react-router. But the two main frameworks used to build new apps today are Next.js and TanStack Start, both NOT using react-router. Although it's possible to integrate RA with Next.js (by opting out of SSR and using a HashRouter), it's cumbersome. It's impossible to do it with TanStack Start.

Solution

Add a routing abstraction layer to allow react-admin to use another router.

Add a TanStack Router implementation to check that the abstraction works for at least 2 routers.

import { Admin, Resource, ListGuesser, tanStackRouterProvider } from 'react-admin';
import { dataProvider } from './dataProvider';

const App = () => (
    <Admin
        dataProvider={dataProvider}
        routerProvider={tanStackRouterProvider}
    >
        <Resource name="posts" list={ListGuesser} />
        <Resource name="comments" list={ListGuesser} />
    </Admin>
);

export default App;

How To Test

React-admin should use react-router by default, and nothing should be broken. The demo apps should work as before.

A demo app powered by TanStack Router was added:

http://localhost:9010/?path=/story/react-admin-frameworks-tanstack--full-app

It contains CRUD routes and custom routes, as well as sub-routes (TabbedForm) and blocker (useWarnWhenUnsavedChanges). All routing features should work, and are covered by integration tests.

The same demo app can be tested in a second story, where it's embedded into an existing TanStack router app:

http://localhost:9010/?path=/story/react-admin-frameworks-tanstack--embedded

In this case, react-admin doesn't create a router but adds its own routes.

Note: these stories don't reset their route properly, so navigating from one to the other will fail. Refresh the browser when opening one of TanStack router's stories.

Reviewing this PR

This is a large PR, so I rebased the history to allow reviewers to read it commit-by-commit.

The tests should pass at the end of each commit.

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

@fzaninotto fzaninotto added the RFR Ready For Review label Jan 2, 2026
Copy link
Collaborator

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Awesome work 💪

  • react-admin still has a dependency on react-router so users that want TanStack Router will have both routers installed. This is probably a breaking change for some people though.
  • TanStack router stories conflict with each other. If you navigate from some deep link in one to another story, you may end up with an empty screen.
  • We should probably split tan stack related code in multiple files, only re-export the provider from ra-core and make the rest available under a sub-path export (https://github.com/colinhacks/zshy/?tab=readme-ov-file#2-specify-your-entrypoints-in-packagejsonzshy)

Comment on lines +48 to +49
import { tanStackRouterProvider } from 'ra-core';
const { Route } = tanStackRouterProvider;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could have a sub-export path to make this more natural: import { Route } from 'ra-core/tanstack';


See the [TanStack Router documentation](./TanStackRouter.md) for more details.

## Using React-Admin In A Sub Path
Copy link
Collaborator

Choose a reason for hiding this comment

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

The next chapters are react-router specific and will probably make users wonder how thy apply when using TanStack Router. Maybe we should introduce a ReactRouter page.


### History Not Working in Embedded Mode

When embedding react-admin in an existing TanStack Router app, make sure both routers use the same history type. If your parent app uses hash history, react-admin will work correctly. If it uses browser history, set up your routes accordingly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does one setup their routes accordingly?


### History Not Working in Embedded Mode

When embedding ra-core in an existing TanStack Router app, make sure both routers use the same history type. If your parent app uses hash history, ra-core will work correctly. If it uses browser history, set up your routes accordingly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

Comment on lines +118 to +136
const PostCreate = () => {
const navigate = useNavigate();
return (
<div style={{ padding: 20 }}>
<h2>Create Post</h2>
<form>
<div>
<label>Title:</label>
<input />
</div>
<div>
<label>Body:</label>
<textarea />
</div>
</form>
<button onClick={() => navigate('/posts')}>Cancel</button>
</div>
);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

A real create would be better here, it feels buggy otherwise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

3 participants