Router set up for a complex app
I am building a project management app that has an "internal" view and an "external" view.
The internal view is served at
app.my-company.com
and the external view is served at subdomain.my-company.com
where subdomain
is our customer's slug.
I want to serve different routes in the internal view and the external view. Currently I have the same repo deployed on all subdomains and in my CRA + react router setup, I serve either the internal routes (if it is a reserved subdomain) of the external routes (if there is a non-reserved subdomain).
This feels whole set up feels quite hacky. I wanted to get an idea if I should have a monorepo where the external subdomains serve one app vs the internal subdomains serve another and then there's another app where I have the common components from both apps. Or I might be completely off and there's a better way to do this! Would love to get your thoughts.
Another point - if I am serving the routes based on the subdomain, I don't see how I'd be able to use file based routing. Right?4 Replies
sensitive-blue•11mo ago
can you please describe in more detail the relation between internal and external parts? do they contain common routes, do they link to each other etc
other-emeraldOP•11mo ago
Yes my bad! They do contain some common routes. They do not link to each other in any way.
So for those common routes I currently check whether the subdomain is external or not and then accordingly display things but it feels janky. If I split the routes it will be cleaner but then there is the issue of duplicating stuff OR making common components which can be used in both
Just not sure which way to go
sensitive-blue•11mo ago
we currently don't have a way of merging separate route trees. looking into this but currently not a priority
genetic-orange•11mo ago
@jairrard IIRC there is an example of monorepo in tanstack start, where you can separate your routes in a package and share it with other apps, maybe you can take a look at that.
but if your current codebase is not monorepo, I would not recommend change your whole codebase just to archive this, maybe use beforeLoad or anything else provided by router to check external/internal state instead.