{"record":{"id":"76ec944c8ce7f897","repo":"sveltejs/kit","slug":"argument-passed-to-preloadcode-must-be-a-route-id","errorCode":null,"errorMessage":"argument passed to preloadCode must be a route ID (i.e. \"/blog/[slug]\" rather than \"blog/[slug]\")","messagePattern":"argument passed to preloadCode must be a route ID \\(i\\.e\\. \"/blog/\\[slug\\]\" rather than \"blog/\\[slug\\]\"\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/client/client.js","lineNumber":2858,"sourceCode":" * [`match`](https://svelte.dev/docs/kit/$app-paths#match) from `$app/paths`:\n *\n * ```js\n * import { match } from '$app/paths';\n * import { preloadCode } from '$app/navigation';\n *\n * const matched = await match('/blog/hello-world');\n * if (matched) await preloadCode(matched.id);\n * ```\n *\n * Unlike `preloadData`, this won't call `load` functions.\n * Returns a Promise that resolves when the modules have been imported.\n *\n * @param {import('$app/types').RouteId} id\n * @returns {Promise<void>}\n */\nexport async function preloadCode(id) {\n\tif (DEV && id[0] !== '/') {\n\t\tthrow new Error(\n\t\t\t`argument passed to preloadCode must be a route ID (i.e. \"/blog/[slug]\" rather than \"blog/[slug]\")`\n\t\t);\n\t}\n\n\tconst route = __SVELTEKIT_CLIENT_ROUTING__\n\t\t? routes.find((r) => r.id === id)\n\t\t: (route_id_cache.get(id) ?? (await load_route_by_id(id)));\n\n\tif (route === ENDPOINT_ONLY) {\n\t\tif (DEV) {\n\t\t\tconsole.warn(\n\t\t\t\t`'${id}' has no \\`+page\\`, so there is no code to preload. If you meant to warm up an ` +\n\t\t\t\t\t`endpoint, request it with \\`fetch\\` instead.`\n\t\t\t);\n\t\t}\n\n\t\treturn;\n\t}","sourceCodeStart":2840,"sourceCodeEnd":2876,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/client.js#L2840-L2876","documentation":"preloadCode() expects a route ID in the framework's internal format, which always starts with a leading slash and includes bracketed parameters (e.g. \"/blog/[slug]\"). In DEV a missing leading slash throws immediately with guidance; a wrong-format ID would otherwise silently match no route.","triggerScenarios":"preloadCode('blog/[slug]') — omitting the leading slash; passing a URL path with real values like '/blog/hello' instead of the parameterized route ID.","commonSituations":"Confusing route IDs with URLs; building the argument from user-facing paths; copying route segments without the leading '/'.","solutions":["Prefix the argument with '/' and use the parameterized form: '/blog/[slug]'","Derive route IDs from your src/routes directory structure, not runtime URLs","Handle runtime parameter values with preloadData instead of preloadCode"],"exampleFix":"// before\nawait preloadCode('blog/[slug]');\nawait preloadCode('/blog/hello');\n// after\nawait preloadCode('/blog/[slug]');","handlingStrategy":"validation","validationCode":"function assertRouteId(id) {\n  if (typeof id !== 'string' || id[0] !== '/') throw new TypeError('route ID must start with /');\n  return id;\n}\nawait preloadCode(assertRouteId('/blog/[slug]'));","typeGuard":"function isRouteId(s) { return typeof s === 'string' && s.startsWith('/'); }","tryCatchPattern":null,"preventionTips":["Always pass parameterized, slash-prefixed route IDs","Use runtime URLs with preloadData, static route IDs with preloadCode","Derive IDs from the src/routes tree in tests"],"tags":["preload","routing","developer-error"],"backgroundTag":"invalid-route-id","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}