withastro/astro · error · Error

Invalid route ${file} — parameter name must match /^[a-zA-Z0

Error message

Invalid route ${file} — parameter name must match /^[a-zA-Z0-9_$]+$/

What it means

getParts() in create-manifest.ts rejected a dynamic route segment whose bracketed parameter name is invalid. Parameter names inside [...] must match /^(?:\.{3})?[\w$]+$/ — letters, digits, underscore, and dollar sign, optionally prefixed by ... for rest params. The throw is a plain Error (not AstroError) raised during manifest generation.

Source

Thrown at packages/astro/src/core/routing/create-manifest.ts:61

const ROUTE_DYNAMIC_SPLIT = /\[([^[\]()]+(?:\([^)]+\))?)\]/;
const ROUTE_SPREAD = /^\.{3}.+$/;

export interface RouteEntry {
	path: string;
	isDir: boolean;
}

function getParts(part: string, file: string) {
	const result: RoutePart[] = [];
	part.split(ROUTE_DYNAMIC_SPLIT).map((str, i) => {
		if (!str) return;
		const dynamic = i % 2 === 1;

		const [, content] = dynamic ? /([^(]+)$/.exec(str) || [null, null] : [null, str];

		if (!content || (dynamic && !/^(?:\.\.\.)?[\w$]+$/.test(content))) {
			throw new Error(`Invalid route ${file} — parameter name must match /^[a-zA-Z0-9_$]+$/`);
		}

		result.push({
			content,
			dynamic,
			spread: dynamic && ROUTE_SPREAD.test(content),
		});
	});

	return result;
}
/**
 * Checks whether two route segments are semantically equivalent.
 *
 * Two segments are equivalent if they would match the same paths. This happens when:
 * - They have the same length.
 * - Each part in the same position is either:
 *   - Both static and with the same content (e.g. `/foo` and `/foo`).

View on GitHub (pinned to d081033d5f)

Solutions

  1. Rename the file so the bracketed name uses only [A-Za-z0-9_$], e.g. [slugId].astro.
  2. For rest params keep the ... prefix directly attached: [...slug].astro.
  3. Remove empty brackets or stray characters from the filename.

Example fix

// before — src/pages/blog/[post-id].astro

// after — src/pages/blog/[postId].astro
Defensive patterns

Strategy: validation

Validate before calling

function isValidParamName(content: string): boolean {
  return /^(?:\.\.\.)?[\w$]+$/.test(content);
}
// validate bracketed names when generating route files

Type guard

function isValidRouteParam(name: string): boolean {
  return /^(?:\.\.\.)?[A-Za-z0-9_$]+$/.test(name);
}

Prevention

When it happens

Trigger: A file like src/pages/[slug-id].astro (hyphen), [slug.json].astro, [123].astro, or an empty [] bracket; using spaces, dots, or special chars inside the brackets; a rest param like [...slug id].astro.

Common situations: Typing a hyphen or dot in a param name; copying a REST-style :slug-id pattern into Astro; tooling auto-generating filenames with disallowed characters.

Related errors


AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12). Data as JSON: /api/errors/dd39a050f2565d27. Report an issue: GitHub.