Add router abstraction and TanStack Router adapter #11102
+5,811
−537
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
masterfor a bugfix or a documentation fix, ornextfor a feature