sveltejs/kit · error · Error
Missing parameter '${name}' in route ${id}
Error message
Missing parameter '${name}' in route ${id} What it means
`resolve_route` builds a concrete path/route id by substituting parameter values into a parsed route pattern. When a required (non-optional, non-rest) parameter is `undefined` (or an empty string) in the params object, the resulting route would be malformed, so this error names the missing parameter and the route id being resolved.
Source
Thrown at packages/kit/src/utils/routing.js:310
* @returns {string}
*/
export function resolve_route(id, params) {
const segments = get_route_segments(id);
const has_id_trailing_slash = id != '/' && id.endsWith('/');
return (
'/' +
segments
.map((segment) =>
segment.replace(segment_pattern, (_, escape_type, escape_code, optional, rest, name) => {
if (escape_type) return encode_pathname_chars(decode_escape_sequence(escape_code));
const value = params[name];
if (value === undefined || value === '') {
if (optional) return '';
if (rest && value !== undefined) return '';
throw new Error(`Missing parameter '${name}' in route ${id}`);
}
if (typeof value === 'string') {
if (value.startsWith('/') || value.endsWith('/')) {
throw new Error(
`Parameter '${name}' in route ${id} cannot start or end with a slash -- this would cause an invalid route like foo//bar`
);
}
return value;
}
if (
typeof value === 'number' ||
typeof value === 'boolean' ||
typeof value === 'bigint'
) {
return String(value);View on GitHub (pinned to 03f1687fe6)
Solutions
- Provide a value for every required parameter when resolving the route
- Make the parameter optional in the route id (`[x?]`) if it can legitimately be absent
- Handle empty-string inputs before resolution (treat them as absent and adjust the route or params)
Example fix
// before
resolve_route('/blog/[slug]/edit', pattern, {});
// after
resolve_route('/blog/[slug]/edit', pattern, { slug: 'hello-world' }); Defensive patterns
Strategy: validation
Validate before calling
function requireParams(routeId, params) {
for (const m of routeId.matchAll(/\[(?!\.\.\.)([^=\]]+?)(?:\?)?\]/g)) {
const name = m[1];
if (params[name] === undefined || params[name] === '') {
throw new Error(`Missing parameter '${name}' for route ${routeId}`);
}
}
} Type guard
function hasAllParams(routeId, params) {
return [...routeId.matchAll(/\[(?!\.\.\.)([^=\]]+?)\]/g)].every((m) => params[m[1]] !== undefined && params[m[1]] !== '');
} Try / catch
try {
const href = resolveRoute(id, pattern, params);
} catch (e) {
if (e.message.startsWith('Missing parameter')) {
const name = e.message.match(/'([^']+)'/)[1];
// supply params[name] or fall back to another route
}
throw e;
} Prevention
- Build params objects from the route id's parsed segments, not by hand
- Treat empty form/query strings as absent before resolving
- Update all call sites when adding a parameter to a route id
When it happens
Trigger: Calling route resolution (e.g. `resolve_route(route.id, route.pattern, params)`) with a params object that omits a required parameter or supplies `''` for it, and the parameter is neither optional (`[x?]`) nor a valid rest segment (`[...x]`).
Common situations: Programmatically generating hrefs/route ids while forgetting one parameter; a rest param handler returning undefined unexpectedly; refactoring route ids to add a parameter without updating all `resolve_route`-style call sites; empty-string values from form/query handling.
Related errors
- Parameter '${name}' in route ${id} cannot start or end with
- Parameter values must be a string, number, boolean, or bigin
- Invalid param definition
- Missing params for dynamic route ID ${id}
- No matcher found for parameter '${name}'${file ? ` in ${file
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/8365fa23a7a6fc3c.
Report an issue: GitHub.