Handling subdomains in Nuxt 3 #16142
-
Hey, In my application, I'd like to have some of the routes/pages on a different subdomain. Most of the articles about handling multiple subdomains in one Nuxt app require Is there any other way to tackle that? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 34 replies
-
While you can't replace the full router, routes and history are modifiable via |
Beta Was this translation helpful? Give feedback.
-
@danielroe @SoftLaza @tasiotas based on what user entered in url I hope it solve the issue, and if you have better idea about implementing please let's communicate more <3 |
Beta Was this translation helpful? Give feedback.
-
Hi there! I used the solutions suggested here as a guideline for setting up subdomains in my nuxt 3 app. But I am currently facing an issue where vue router breaks when I navigate the subdomain pages using NuxtLink. Although, the intended page shows on refresh of the browser tab I would be glad if I could be pointed in the direction of a fix for this. Thank you |
Beta Was this translation helpful? Give feedback.
-
Hello,
Code that enables this in the nuxt app:
Then in your page module you can check if the returned slug is valid or not.
In your case i think you want only some specific routes to be served on the subdomain. for that you can simply put another check in the composable itself or convert the composable into a plugin and put an additional check using useRouter() Note: the composable i suggested allows for subdomains and top level domains to co-exist you can disable that based on your requirement. Server config that secures this setup
If you are not using dynamic subdomains and top level domains then putting in these checks becomes much simpler. I have used this setup with edge deployments on cloudflare workers, standard vanilla setup on nginx + node deployments and kubernetes. Hope this helps people that are trying to run subdomains and multiple custom domains on nuxt 3. |
Beta Was this translation helpful? Give feedback.
-
Any update on this? Found this https://github.com/hieuhani/nuxt-multi-tenancy |
Beta Was this translation helpful? Give feedback.
-
I ended up refactoring out the tenant part out of the main app. Now I have 2 projects on Vercel on a monorepo.
I am not using any module though. The tenant app checks the subdomain or a custom domain against the database, and sets it in Nitro context and then on every route request we can fetch the correct tenant using the context. |
Beta Was this translation helpful? Give feedback.
See https://zernonia.keypress.blog/why-keypress