Capítulo 62 de 456
Micro-frontend approach that splits one large domain into multiple independent Next.js applications ("zones"), each serving a distinct set of paths, deployed and developed separately but appearing as one site to the user.
assetPrefix so its static assets don't collide with other zones' assets on the same domain.assetPrefix: next.config.js option that prefixes a zone's JS/CSS under /assetPrefix/_next/...; the default (catch-all) zone doesn't need one.rewrites() for routing: the recommended way to route incoming paths to the correct zone's domain, minimizing latency versus a proxy.<a> tag, not <Link>, since <Link> tries to prefetch/soft-navigate relative paths, which fails across zone boundaries.serverActions.allowedOrigins: required config when using Server Actions with Multi-Zones, since the user-facing domain serves multiple apps.// next.config.js — defining a zone's asset prefix
/** @type {import('next').NextConfig} */
const nextConfig = {
assetPrefix: '/blog-static',
}
// next.config.js — routing zones via rewrites in the entry app
async rewrites() {
return [
{
source: '/blog',
destination: `${process.env.BLOG_DOMAIN}/blog`,
},
{
source: '/blog/:path+',
destination: `${process.env.BLOG_DOMAIN}/blog/:path+`,
},
{
source: '/blog-static/:path+',
destination: `${process.env.BLOG_DOMAIN}/blog-static/:path+`,
}
];
}
// proxy.js — dynamic zone routing decision
export async function proxy(request) {
const { pathname, search } = request.nextUrl
if (pathname === '/your-path' && myFeatureFlag.isEnabled()) {
return NextResponse.rewrite(`${rewriteDomain}${pathname}${search}`)
}
}
<Link> para navegar entre zonas: falha porque o prefetch/soft navigation não funciona cross-zone; usar <a>.serverActions.allowedOrigins: Server Actions rejeitam a origem do domínio user-facing compartilhado entre zonas se não for explicitamente permitida.Not applicable — no tabular reference in source beyond the config snippets above.
rewrites() é preferível a proxy para roteamento estático entre zonas por ter menor latência; proxy só quando a decisão precisa ser dinâmica._next/...); versões anteriores precisavam.