Multi-Zone Application Setup
Compose multiple Next.js apps under one domain using rewrites for micro-frontend architecture.
// Main app: next.config.ts
import type { NextConfig } from 'next';
const config: NextConfig = {
async rewrites() {
return {
beforeFiles: [
// Route /blog/* to the blog app
{
source: '/blog/:path*',
destination: 'https://blog.internal.example.com/blog/:path*',
},
// Route /docs/* to the docs app
{
source: '/docs/:path*',
destination: 'https://docs.internal.example.com/docs/:path*',
},
],
};
},
};
export default config;
// Blog app: next.config.ts
const blogConfig: NextConfig = {
basePath: '/blog',
};
export default blogConfig;Sponsored
Deploy on Vercel — Multi-Zone Support Built In
Use Cases
- Team-owned sub-apps
- Incremental migration
- Domain consolidation
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Compound Component Pattern
Build flexible compound components using React Context for implicit parent-child communication.
Render Prop Pattern
Share stateful logic between components using the render prop pattern for maximum flexibility.
Type-Safe API Route Handler
Next.js App Router route handler with input validation, typed responses, and proper error handling.
Authentication Middleware Guard
Next.js middleware that checks auth tokens on protected routes and redirects unauthenticated users to login.