vercel/next.js · error · Error

Catch-all must be the last part of the URL.

Error message

Catch-all must be the last part of the URL.

What it means

_insert throws while adding a route whose catch-all segment [...slug] is not the final segment of the path. A catch-all consumes every remaining segment, so any segment after it could never match; the router validates this as each route path is inserted into the sorted tree.

Source

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

          ._smoosh(`${prefix}[[...${this.optionalRestSlugName}]]/`)
      )
    }

    return routes
  }

  private _insert(
    urlPaths: string[],
    slugNames: string[],
    isCatchAll: boolean
  ): void {
    if (urlPaths.length === 0) {
      this.placeholder = false
      return
    }

    if (isCatchAll) {
      throw new Error(`Catch-all must be the last part of the URL.`)
    }

    // The next segment in the urlPaths list
    let nextSegment = urlPaths[0]

    // Check if the segment matches `[something]`
    if (nextSegment.startsWith('[') && nextSegment.endsWith(']')) {
      // Strip `[` and `]`, leaving only `something`
      let segmentName = nextSegment.slice(1, -1)

      let isOptional = false
      if (segmentName.startsWith('[') && segmentName.endsWith(']')) {
        // Strip optional `[` and `]`, leaving only `something`
        segmentName = segmentName.slice(1, -1)
        isOptional = true
      }

      if (segmentName.startsWith('…')) {

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Move the catch-all segment [...slug] to the end of the route path.
Defensive patterns

Strategy: validation

When it happens

Trigger: A catch-all segment is not the last part of the route.

Common situations: A route like /docs/[...slug]/edit where the catch-all is followed by more segments.


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