Issue with Link Component Typing When Generating Routes Programmatically #2433
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
if you build the route tree by looping over the array, TS types cannot be inferred. you must explicitly define each route just like the docs explain it: https://tanstack.com/router/latest/docs/framework/react/guide/code-based-routing |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks a lot for the quick response! I think I’ll stick with the trade-off of less perfect typing in favor of keeping my centralized route definitions—it works better for my use case :) For anyone else running into similar TypeScript issues, you can always rely on general types like AnyRoute or AnyRouteMatch as a workaround. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Hi, do you generate your routes in a component? I'm having trouble generating routes in component, because I need to get the route paths from backend after the user logged in, I only create some routes like login page globally. However, when I add some new routes in useEffect hook, the added route paths are not found, I need to re-initialize the router in my Router component. Is there a recommend way to add children route in a fetch api call? |
Beta Was this translation helpful? Give feedback.
if you build the route tree by looping over the array, TS types cannot be inferred. you must explicitly define each route just like the docs explain it:
https://tanstack.com/router/latest/docs/framework/react/guide/code-based-routing