T
TanStack12mo ago
absent-sapphire

url rewrites support

Does TanStack Start support URL rewrites similar to how it's done in Next.js middleware? My use case is for a multi-tenant application which supports Sub domain routing
49 Replies
fascinating-indigo
fascinating-indigo12mo ago
didn't try, but this should work: https://vinxi.vercel.app/guide/route-rules.html
Route Rules | Vinxi
Vinxi Documentation
correct-apricot
correct-apricot12mo ago
curious as well tho last time I asked Tanner he mentioned a possible solution via <base> or something like that at some point 🤞
ambitious-aqua
ambitious-aqua11mo ago
Deeply invested in this if I am to rewrite a project. Will come back if I get anything working, but would welcome any other insight. Route rules doesn't seem to work. Trying it with a proxy domain (test.local for example) and it doesn't seem to work with subdomains (foo.test.local).
correct-apricot
correct-apricot11mo ago
Quoting @Tanner Linsley "We would need to build this new rewrite functionality. It would be similar to base, but dynamic". Think support for this for multi-tenancy or whatever would be a huge +. Remix doesn't support it as far as I know, so NextJS has kinda an edge on that still
ambitious-aqua
ambitious-aqua11mo ago
Hmm, thank you for the additional context @CanRau. It is unforunate, but understandable. I am early enough for a potential rewrite, but that will have to wait for general stability + this feature.
extended-salmon
extended-salmon11mo ago
Could we get a more specific RFC style write up on this feature? E.g. a comprehensive list of expectations?
eastern-cyan
eastern-cyan11mo ago
this is possible with SolidStart's router with a bit of configuration. not sure if it needs to be directly involved with vinxi but here's a nice article about it along with other frameworks: https://egoist.dev/multi-tenant-web-app-2024#solid-start
correct-apricot
correct-apricot11mo ago
not an RFC (yet) tho just found this related discussion https://github.com/TanStack/router/discussions/1076
GitHub
Parameters for the root path? · TanStack router · Discussion #1076
Is it possible to add a common path prefix to every route with file-based routing? eg. in a multi-tenant / multi-login app, every path starts with eg. /user/12345/project/12345. As far as I see, th...
stormy-gold
stormy-gold8mo ago
Aha, so I guess this answers my question from here https://discord.com/channels/719702312431386674/1329455809603702885/1329455809603702885 Would really love to see this, as then it'll make Start a viable option for us to migrate off of Next. Our entire SaaS relies on multi tenancy and custom domain support for our users
extended-salmon
extended-salmon8mo ago
Again, if we can get even the smallest form of an RFC that covers as many cases as we can brainstorm here, I can start on it
stormy-gold
stormy-gold8mo ago
Have thrown something together quite roughly here. Now I'm no full time backend dev by any stretch, but hopefully it lays some ground work.
deep-jade
deep-jade8mo ago
how do other frameworks handle this? I think doing this after route matching is too late
extended-salmon
extended-salmon8mo ago
It needs to be before route matching basically we need to have some injectable rules into the router that let you spoof the internal URL and links to something different that doesn't change the internal impl much if at all.
extended-salmon
extended-salmon8mo ago
GPT, aggregate!!!
ambitious-aqua
ambitious-aqua8mo ago
Thanks Tommerty. Any bit helps. As soon as this feature drops I am initializing a long-awaited project. 🫡
extended-salmon
extended-salmon8mo ago
So essentially, we need: - A way to transform the URL coming in (including host name, etc) to something else that we then consider the source of truth - This transformation and subsequent navigations should retain the current URL structure (and not use the interpreted URL)
stormy-gold
stormy-gold8mo ago
Purdy much! So like on the Next multi-tenant example there's the route for [domain] which would then be set as a users domain from the middleware (all linked in the RFC). That's really the primary gist of it for the most part. As someone who enjoys file based routing I feel like it's a clean simple way to outline what routes do what. But again, I'm not a backend guy but frontend, and a founder who's sick of Next and needs to convince his backend team that there's light at the end of the Tanstack tunnel 😅
extended-salmon
extended-salmon8mo ago
I think this is doable The funnel that URLs flow through is a tight one that we control really well We already do route masking, too This isn't too different
ambitious-aqua
ambitious-aqua5mo ago
Would it be rude to get an idea if we are getting near on implementing this? I only ask cause I am a decision point between this and Next. Since I am (mostly) front end guy I don't have nearly the skills to chop a PR up, otherwise that would be my main priority rn. but since I am not otherwise contributing, please feel no hesitation on telling me "no, scram". 😆
deep-jade
deep-jade5mo ago
do we have a clear picture yet what is needed API wise?
ambitious-aqua
ambitious-aqua5mo ago
All we have is what is listed above. A basic RFC and some light discussions on the needs
deep-jade
deep-jade5mo ago
does any of this talk about the "reversability" of such a rewrite? what I mean by that is that for creating links, we would need to know how to build the link , while for the request, we would need to map it to some route and is there prior art for this specific part?
deep-jade
deep-jade5mo ago
e.g. https://svelte.dev/docs/kit/hooks#Universal-hooks-reroute seems to capture one direction of mapping
Hooks • Docs • Svelte
Hooks • Svelte documentation
ambitious-aqua
ambitious-aqua5mo ago
tbh in my head it was always one way mapping. but probably I was just thinking about subdomain mapping where links just obey primary (sub)domain per usual on the "reversability"/two-way, not that I have seen
ambitious-aqua
ambitious-aqua5mo ago
this was linked previously on a rundown on some basic subdomain rewrites in other frameworks: https://egoist.dev/multi-tenant-web-app-2024
EGOIST
Building a Multi-Tenant Web App in 2024
A blog about small things.
ambitious-aqua
ambitious-aqua5mo ago
i am just a mere front end dev, but I can see the complications here. especially for type generation too.
dependent-tan
dependent-tan5mo ago
I too am very keen to have this rewrite/redirect functionality - Are there any updates? Currently I've not found another framework that provides a similar level of DX when using subdomain routing. Looking at tanstack so far the DX is so close and enjoyable, with subdomain routing it would be suitable for my multitenant usecase
ambitious-aqua
ambitious-aqua5mo ago
I know Tanner was going to work on it but other things probably got in the way. which is understandable. in any case i don't think there is any traction on it cause I don't see a PR started
eastern-cyan
eastern-cyan5mo ago
Tanner Linsley (@tannerlinsley) on X
We're right in the middle of "devinxi" (removing Vinxi from @Tan_Stack Start for just Vite + Nitro + h3), and we decided to give Start some awesome quality of life improvements while we're in the guts of it. Here's *some* of the lower hanging fruit (there's even more): - Jumping
X
eastern-cyan
eastern-cyan5mo ago
Easier rewrites, redirects and proxying
ambitious-aqua
ambitious-aqua4mo ago
Yeah good catch this is the key. But it sounds like it could be during devinxi 🙏
extended-salmon
extended-salmon4mo ago
We could easily support rewrites FROM custom url structures, but the key is keeping them when users navigate. You need to be able to write back to the custom format.
quickest-silver
quickest-silver4mo ago
stumbled onto this thread with the same intent... can i migrate to TanStack Router/Start w/ my multi-tenant setup. I came across a blog post and starter kit from 2024 and was curious if they were relevant or not quite. https://saas-ui.dev/blog/building-a-multi-tenant-b2b-saas-with-vite-tanstack-router#resources https://saas-ui.dev/blog/tanstack-router-saas-starter-kit#saas-starter-kit-features If they are helpful I'm happy to add to the RFC
Saas UI: An advanced component library for SaaS companies.
Building a multi-tenant B2B SaaS with Vite, Tanstack React Router a...
In this article, we'll start building a multi-tenant B2B SaaS using Vite, Tanstack React Router, React Query, Chakra UI and Saas UI.
Saas UI: An advanced component library for SaaS companies.
TanStack Router SaaS Starter Kit
TanStack Router SaaS starter kit is now available.
deep-jade
deep-jade4mo ago
where does it say something about rewrites?
quickest-silver
quickest-silver4mo ago
@Manuel Schiller it might not - haven't dug too deep into it. Hm, mebbe i goofed the thread overview, just saw that it was opened for a multi-tenant use case sorry if i super misunderstood tho!
deep-jade
deep-jade4mo ago
rewrites would enable that multitenant setup better so its related
quickest-silver
quickest-silver4mo ago
ah - gotcha. would ya think it's sorta possible currently. (the multi tenant use-case)
deep-jade
deep-jade4mo ago
we still need to figure out rewrites as you see not an area of active development right now, but we'll eventually get there
national-gold
national-gold2mo ago
Would also love to see this as soon as possible, it would enable easily configuring a reverse proxy for observability and analytics
ambitious-aqua
ambitious-aqua2mo ago
Lots of wins if this were to come through, but I'd venture to say the biggest would be for B2B and B2C apps that heavily use subdomains and even custom domains.
rising-crimson
rising-crimson3w ago
just come across this limitation after switching a B2B app from nextjs a while back and now having a client require their own domain. has anyone got temporary solution for serving the same app under multiple domains until rewrite support is added? was thinking of just hosting multiple instances of the app but would require a decent amount of rewriting and feels quite janky
absent-sapphire
absent-sapphire3w ago
GitHub
Is there a way to have Rewrites or Proxy? · TanStack router · Dis...
This might be a dumb question, but I couldn&#39;t find any docs for it, so I might as well ask. My team is moving away from nextjs (pages) and moving to TSR (tanstack router with start/vinxi). One ...
rising-crimson
rising-crimson3w ago
yeah already run into the issue with proxy only working in dev when trying to proxy posthog requests haha
eastern-cyan
eastern-cyan2w ago
christmas is coming early this year
eastern-cyan
eastern-cyan2w ago
GitHub
feat: url rewrites by tannerlinsley · Pull Request #5029 · TanSta...
Summary by CodeRabbit New Features Location objects now include a URL object and fullPath; internal links use url.href. Added optional URL rewrite hooks for reading and writing locations. Browser...
ambitious-aqua
ambitious-aqua4d ago
Ahhhhhhhhhhh That PR was closed but another was merged into alpha

Did you find this page helpful?