next-zonesv0.1.0

Routing rules: a zone's headers, redirects and rewrites

A zone keeps its own headers(), redirects() and rewrites() in its next.config, as any Next app does. They apply when the zone runs alone and when it is served together with other zones.

export default zoneConfig({
  mount: "/blog",
  async headers() {
    return [{ source: "/blog/api/:path*", headers: [{ key: "x-zone", value: "blog" }] }];
  },
  async redirects() {
    return [{ source: "/blog/old/:id", destination: "/blog/:id", permanent: true }];
  },
  async rewrites() {
    return {
      beforeFiles: [{ source: "/blog/b/:id", destination: "/blog/:id" }],
      afterFiles: [{ source: "/blog/a/:id", destination: "/blog/:id" }],
      fallback: [{ source: "/blog/f/:path*", destination: "/blog/docs/:path*" }],
    };
  },
});

What applies#

Everything Next supports in these rules:

They keep Next's order: headers and redirects run before the shell's proxy.ts; rewrites run after it.

Intercepting routes ((.)photo, (..)photo) work too, since Next turns them into rewrites.

Rules#

Edit this page on GitHub · Markdown