Replies: 1 comment
-
I’m integrating Tanstack router into an existing monorepo and came across this same problem. We have a top level app where all the routes are defined. We also have lots of lower level libraries that would really benefit from the strong typing that Tanstack router provides. My current approach to this problem is to create a router lib in our monorepo. This lib doesn’t have any references back to the app. Instead, we created a specialized build step that “air drops” the router’s d.ts file into the package. We’ve added a custom vite plugin to make sure this happens whenever the route definition itself changes. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The problem
Hi! We have quite a large monorepo where we are using TanStack Router for one of our new apps. We're loving this new world of typesafe routing, and would like to take it a step further - to have typesafe routing even across different applications
For example, let's imagine in our monorepo we have two packages:
emails
which is a library containing templates for the various emails we send in our appsadmin
which is an admin panel app we are using TanStack Router inLet's say we have some promotional emails where we want to include a link to our Admin app - for example something like
Traditionally this has been quite hard to keep typesafe: if we would for example decide to change our
/manage-things
route to a simpler/manage
, the above email would break and we couldn't get any help from TypeScript to catch this sort of thing.However, now that the full route tree of the Admin app is generated inside the Admin package, we could merely import
/admin/routeTree.gen.ts
and actually be able to dynamically build the link in the email - maybe something like this:But there's one small problem - this introduces a dependency on essentially the full
admin
package inemails
, since therouteTree.gen.ts
file imports all of the route definitions.Desired end state
Would be amazing if it would be possible to get a route tree file that is "disconnected" from the actual files that it's based on, such that it would essentially just be a file consisting of compiled types, and wouldn't include any actual code from the app. We would then be able to simply copy these compiled route trees to a separate package that all of our apps depend on, and voilà - typesafe cross-app communication.
Personal opinion: being able to build these sorts of typesafe APIs for cross-app communication would be an absolute game changer and we would really have to consider migrating all of our apps to use TSR.
Has someone ran into the same problem? Have you already found a way to achieve this? Is this potentially already on the roadmap?
Beta Was this translation helpful? Give feedback.
All reactions