sveltejs/kit · error

Invalid route ${id} — a rest route segment is always optiona

Error message

Invalid route ${id} — a rest route segment is always optional, remove the outer square brackets

What it means

Route ID validation error: the id contains '[[...', i.e. a rest parameter written with double brackets like [[...slug]]. Rest parameters are inherently optional in SvelteKit, so the extra optional-marking brackets are redundant and invalid; the correct form is [...slug]. Fires during route walking in sync/dev.

Source

Thrown at packages/kit/src/core/sync/create_manifest_data/index.js:186

			}

			if (count_occurrences('[', id) !== count_occurrences(']', id)) {
				throw new Error(`Invalid route ${id} — brackets are unbalanced`);
			}

			if (/#/.test(segment)) {
				// Vite will barf on files with # in them
				throw new Error(`Route ${id} should be renamed to ${id.replace(/#/g, '[x+23]')}`);
			}

			if (/\[\.\.\.[\w-]+\]\/\[\[/.test(id)) {
				throw new Error(
					`Invalid route ${id} — an [[optional]] route segment cannot follow a [...rest] route segment`
				);
			}

			if (/\[\[\.\.\./.test(id)) {
				throw new Error(
					`Invalid route ${id} — a rest route segment is always optional, remove the outer square brackets`
				);
			}

			const { pattern, params } = parse_route_id(id);

			/** @type {import('types').RouteData} */
			const route = {
				id,
				parent,

				segment,
				pattern,
				params,

				layout: null,
				error: null,
				leaf: null,

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Remove the outer square brackets: rename [[...slug]] to [...slug]
  2. Keep single-bracket rest parameters, since they are always optional by design
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/kit/src/core/sync/create_manifest_data/index.js:186 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/6a22ab18025a97b5. Report an issue: GitHub.