#Multiple Next.js Applications on Same Domain
1 messages · Page 1 of 1 (latest)
Hi @terse pasture. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To serve multiple Next.js applications under a single domain using the App Router, you can use a similar approach to the one you used with basePath in the Pages Router. However, instead of basePath, you will use both rewrites and basePath configurations to achieve a Multi Zone project on Vercel.
Here's an example of how you can set it up:
-
For your main application (let's call it
home), include the rewrites configuration mapping to the other applications (let's sayapp1andapp2) within anext.config.jsfile. This will direct traffic from certain paths to the corresponding applications. -
For
app1andapp2, setbasePathto/app1and/app2respectively in theirnext.config.jsfiles. This ensures that generated pages, Next.js assets, and public assets are within the/app1and/app2subfolders. -
Make sure all pages are unique across zones. For example, the
homeapp should not have apages/app1/index.jspage.
You can see a complete example project implementing Multi Zones here (https://github.com/vercel/next.js/tree/canary/examples/with-zones).
Remember, Next.js uses a file-system based router where folders are used to define routes. Each folder represents a route segment that maps to a URL segment. To create a nested route, you can nest folders inside each other.
For more advanced routing patterns, the App Router provides conventions for Parallel Routes and Intercepting Routes. Parallel Routes allow you to simultaneously show two or more pages in the same view that can be navigated independently. Intercepting Routes allow you to intercept a route and show it in the context of another route.
Sources:
- Vercel Guide (https://vercel.com/guides/how-can-i-serve-multiple-projects-under-a-single-domain)
- Next.js Routing Fundamentals (https://nextjs.org/docs/app/building-your-application/routing)
- Next.js Advanced Routing Patterns (https://nextjs.org/docs/app/building-your-application/routing#advanced-routing-patterns)