{"record":{"id":"c9e247a28f1a0e6f","repo":"sveltejs/kit","slug":"parameter-name-in-route-id-cannot-start-or","errorCode":null,"errorMessage":"Parameter '${name}' in route ${id} cannot start or end with a slash -- this would cause an invalid route like foo//bar","messagePattern":"Parameter '(.+?)' in route (.+?) cannot start or end with a slash -- this would cause an invalid route like foo//bar","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/utils/routing.js","lineNumber":315,"sourceCode":"\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);\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow new Error('Parameter values must be a string, number, boolean, or bigint');\n\t\t\t\t})\n\t\t\t)","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/utils/routing.js#L297-L333","documentation":"When substituting a string parameter into a route pattern, `resolve_route` rejects values that start or end with `/`. Embedding such values would create double or trailing slashes (like `foo//bar`), producing invalid or unintended URLs. The error identifies the offending parameter and route.","triggerScenarios":"Calling route resolution with a param value such as `'/admin'`, `'users/'`, or `'a/b/'` for a non-rest parameter; joining path fragments into a single param instead of using rest parameters.","commonSituations":"Building nested paths from user/config data (e.g. `tenant.basePath` already containing a slash); passing URL-decoded values with leading slashes; misusing a regular `[path]` param where `[...path]` rest syntax is required.","solutions":["Strip leading/trailing slashes from the value before passing it (e.g. `value.replaceAll(/^\\/+|\\/+$/g, '')`)","Use a rest parameter `[...path]` when the value legitimately spans multiple segments","Validate/normalize the source of the value (config, CMS, user input) to never include boundary slashes"],"exampleFix":"// before\nresolve_route(id, pattern, { path: '/settings/profile/' });\n// after\nresolve_route(id, pattern, { path: 'settings/profile' }); // or use [...path] route","handlingStrategy":"validation","validationCode":"function assertNoBoundarySlashes(params) {\n\tfor (const [k, v] of Object.entries(params)) {\n\t\tif (typeof v === 'string' && (v.startsWith('/') || v.endsWith('/'))) {\n\t\t\tthrow new Error(`Param '${k}' must not start or end with '/': ${v}`);\n\t\t}\n\t}\n}","typeGuard":"function isSafePathParam(v) {\n\treturn typeof v !== 'string' || (v.length > 0 && !v.startsWith('/') && !v.endsWith('/'));\n}","tryCatchPattern":"try {\n\tconst href = resolveRoute(id, pattern, params);\n} catch (e) {\n\tif (e.message.includes('cannot start or end with a slash')) {\n\t\tparams = Object.fromEntries(Object.entries(params).map(([k, v]) => [k, typeof v === 'string' ? v.replace(/^\\/+|\\/+$/g, '') : v]));\n\t} else throw e;\n}","preventionTips":["Normalize slash-bearing config/user values (trim boundary slashes) at ingestion time","Use [...rest] parameters for multi-segment values","Never compose nested paths into a single non-rest param"],"tags":["routing","params","url-validation","runtime"],"backgroundTag":"invalid-route-param-slash","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}