sveltejs/kit · error

Invalid route ${id} — an [[optional]] route segment cannot f

Error message

Invalid route ${id} — an [[optional]] route segment cannot follow a [...rest] route segment

What it means

Route ID validation error: the id matches a [...rest] parameter segment immediately followed by an [[optional]] segment (pattern [...x]/[[). Because a rest parameter already greedily matches any remaining path, an optional segment after it is ambiguous and disallowed. Fires during route manifest generation.

Source

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

					return String.fromCodePoint(parseInt(code, 16));
				}
			});

			if (/\]\[/.test(unescaped)) {
				throw new Error(`Invalid route ${id} — parameters must be separated`);
			}

			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,

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Remove or relocate the [[optional]] segment so it does not follow a [...rest] segment
  2. Restructure the routes, e.g. move the optional segment before the rest parameter or into a separate route
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/kit/src/core/sync/create_manifest_data/index.js:180 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/7a7a7c3841ebd38b. Report an issue: GitHub.