vercel/next.js · error · Error

You cannot use both an optional and required catch-all route

Error message

You cannot use both an optional and required catch-all route at the same level ("[[...${this.optionalRestSlugName}]]" and "${urlPaths[0]}").

What it means

Mirror of the required-vs-optional check: a required catch-all [...slug] is being inserted at a level that already has an optional catch-all [[...rest]]. The patterns overlap on every path, so Next.js rejects the combination while building the sorted route tree.

Source

Thrown at packages/next/src/shared/lib/router/utils/sorted-routes.ts:168

        slugNames.push(nextSlug)
      }

      if (isCatchAll) {
        if (isOptional) {
          if (this.restSlugName != null) {
            throw new Error(
              `You cannot use both an required and optional catch-all route at the same level ("[...${this.restSlugName}]" and "${urlPaths[0]}" ).`
            )
          }

          handleSlug(this.optionalRestSlugName, segmentName)
          // slugName is kept as it can only be one particular slugName
          this.optionalRestSlugName = segmentName
          // nextSegment is overwritten to [[...]] so that it can later be sorted specifically
          nextSegment = '[[...]]'
        } else {
          if (this.optionalRestSlugName != null) {
            throw new Error(
              `You cannot use both an optional and required catch-all route at the same level ("[[...${this.optionalRestSlugName}]]" and "${urlPaths[0]}").`
            )
          }

          handleSlug(this.restSlugName, segmentName)
          // slugName is kept as it can only be one particular slugName
          this.restSlugName = segmentName
          // nextSegment is overwritten to [...] so that it can later be sorted specifically
          nextSegment = '[...]'
        }
      } else {
        if (isOptional) {
          throw new Error(
            `Optional route parameters are not yet supported ("${urlPaths[0]}").`
          )
        }
        handleSlug(this.slugName, segmentName)
        // slugName is kept as it can only be one particular slugName

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Keep only one of the optional or required catch-all routes at that level.
Defensive patterns

Strategy: validation

When it happens

Trigger: An optional and a required catch-all route exist at the same level.

Common situations: Having both [[...slug]] and [...slug] (or equivalents) as siblings.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/f6f90a08d6416906. Report an issue: GitHub.