T
TanStack5mo ago
exotic-emerald

Monorepo with multiple routers

I've looked at the monorepo setup, but I'm still not sure how to set things up if i need to have two separate routers, and shared components between them. I'm going to be working with a website and a desktop app which will have some similar features and shared components, but won't be exactly the same. How can I merge the typesafety of multiple routers when creating components? Appreciate any direction that can be given
7 Replies
multiple-amethyst
multiple-amethyst5mo ago
what exactly do you want to "merge" ?
exotic-emerald
exotic-emeraldOP5mo ago
idk if merge is exactly the right word, https://stackblitz.com/github/tanstack/router/tree/main/examples/react/router-monorepo-simple?embed=1&theme=dark&preset=node&file=src/routes/__root.tsx just based on the monorepo example theres only one router defining routes which is then imported into the post-feature section etc. What I'm wondering is with the monorepo setup if theres anyway to have two separate routers that share components?
exotic-emerald
exotic-emeraldOP5mo ago
for example a component like this i need in both the web and the app, but its also needs to be a link
No description
exotic-emerald
exotic-emeraldOP5mo ago
do i just need to use strict: false for everything or is there something i can pass in for props to a component to determine which router API to use maybe
multiple-amethyst
multiple-amethyst5mo ago
cc @Nicolas Beaussart
frail-apricot
frail-apricot5mo ago
If you need to share a component between two routers, I'm not sure there is a good option right now
exotic-emerald
exotic-emeraldOP4mo ago
hmm okay ill try to see if i can work something out My ideal setup would be to have a shared router, and then individual routers for each application, and then somehow be able to merge the shared router/routes with the individual app routers. Almost like how trpc has a mergeRouters function. Not sure if anything like this can be achieved using the existing codebased routing or virtual routing

Did you find this page helpful?