Is RouterProvider recommended for TanStack Router, or should we use _asChild pattern instead? #9450
Unanswered
lyhoang-web-dev
asked this question in
Q&A
Replies: 1 comment 2 replies
-
|
Hi @snowystinger, sorry for annoying you. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
We're integrating React Aria Components with TanStack Router and need guidance on the recommended approach from this link
Current Situation
Your documentation suggests using
RouterProviderwith module declaration:However, this approach loses type safety for required route params and search params.
Problem: Type Safety Loss
Example 1: Missing required params
Example 2: Missing required search params
Root Cause (research from issue below)
RouterConfig.href uses
ToOptionstype, which doesn't enforce validation likeValidateLinkOptionsdoes.Related TanStack Router issue: TanStack/router#5759
Our Workaround:
_asChildPatternWe use TanStack Router's _asChild prop (similar to createLink):
Benefits
✅ Full type safety (params & search validation)
✅ Type errors for missing required fields
✅ Consistent API with TanStack Router
✅ No need for RouterProvider
Usage
You can check example code in here: Stackblitz
Questions
_asChildworkaround acceptable as the primary pattern for Link, MenuItem, Breadcrumb, etc.?Additional Context
Version
Link, with full type safety using _asChildThank you for your guidance! 🙏
Beta Was this translation helpful? Give feedback.
All reactions