vercel/next.js · error · Error

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

Error message

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

What it means

_insert throws when an optional catch-all [[...slug]] is inserted at a level that already has a required catch-all [...rest]. Both patterns match overlapping path sets at that level, so only one catch-all per level is permitted.

Source

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

            throw new Error(
              `You cannot have the same slug name "${nextSlug}" repeat within a single dynamic path`
            )
          }

          if (slug.replace(/\W/g, '') === nextSegment.replace(/\W/g, '')) {
            throw new Error(
              `You cannot have the slug names "${slug}" and "${nextSlug}" differ only by non-word symbols within a single dynamic path`
            )
          }
        })

        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

View on GitHub (pinned to 0eb3775416)

Solutions

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

Strategy: validation

When it happens

Trigger: A required and an optional 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/a697ee1fc5a15574. Report an issue: GitHub.