{"record":{"id":"8365fa23a7a6fc3c","repo":"sveltejs/kit","slug":"missing-parameter-name-in-route-id","errorCode":null,"errorMessage":"Missing parameter '${name}' in route ${id}","messagePattern":"Missing parameter '(.+?)' in route (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/utils/routing.js","lineNumber":310,"sourceCode":" * @returns {string}\n */\nexport function resolve_route(id, params) {\n\tconst segments = get_route_segments(id);\n\tconst has_id_trailing_slash = id != '/' && id.endsWith('/');\n\n\treturn (\n\t\t'/' +\n\t\tsegments\n\t\t\t.map((segment) =>\n\t\t\t\tsegment.replace(segment_pattern, (_, escape_type, escape_code, optional, rest, name) => {\n\t\t\t\t\tif (escape_type) return encode_pathname_chars(decode_escape_sequence(escape_code));\n\n\t\t\t\t\tconst value = params[name];\n\n\t\t\t\t\tif (value === undefined || value === '') {\n\t\t\t\t\t\tif (optional) return '';\n\t\t\t\t\t\tif (rest && value !== undefined) return '';\n\t\t\t\t\t\tthrow new Error(`Missing parameter '${name}' in route ${id}`);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\t\tif (value.startsWith('/') || value.endsWith('/')) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Parameter '${name}' in route ${id} cannot start or end with a slash -- this would cause an invalid route like foo//bar`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn value;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof value === 'number' ||\n\t\t\t\t\t\ttypeof value === 'boolean' ||\n\t\t\t\t\t\ttypeof value === 'bigint'\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn String(value);","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/utils/routing.js#L292-L328","documentation":"`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.","triggerScenarios":"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]`).","commonSituations":"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.","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)"],"exampleFix":"// before\nresolve_route('/blog/[slug]/edit', pattern, {});\n// after\nresolve_route('/blog/[slug]/edit', pattern, { slug: 'hello-world' });","handlingStrategy":"validation","validationCode":"function requireParams(routeId, params) {\n\tfor (const m of routeId.matchAll(/\\[(?!\\.\\.\\.)([^=\\]]+?)(?:\\?)?\\]/g)) {\n\t\tconst name = m[1];\n\t\tif (params[name] === undefined || params[name] === '') {\n\t\t\tthrow new Error(`Missing parameter '${name}' for route ${routeId}`);\n\t\t}\n\t}\n}","typeGuard":"function hasAllParams(routeId, params) {\n\treturn [...routeId.matchAll(/\\[(?!\\.\\.\\.)([^=\\]]+?)\\]/g)].every((m) => params[m[1]] !== undefined && params[m[1]] !== '');\n}","tryCatchPattern":"try {\n\tconst href = resolveRoute(id, pattern, params);\n} catch (e) {\n\tif (e.message.startsWith('Missing parameter')) {\n\t\tconst name = e.message.match(/'([^']+)'/)[1];\n\t\t// supply params[name] or fall back to another route\n\t}\n\tthrow e;\n}","preventionTips":["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"],"tags":["routing","params","runtime"],"backgroundTag":"missing-route-param","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}