{"record":{"id":"448e4bbd38a08818","repo":"sveltejs/kit","slug":"cannot-access-url-property-on-a-page-with-prere","errorCode":null,"errorMessage":"Cannot access url.${property} on a page with prerendering enabled","messagePattern":"Cannot access url\\.(.+?) on a page with prerendering enabled","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/utils/url.js","lineNumber":204,"sourceCode":"\t\tget() {\n\t\t\tthrow new Error(\n\t\t\t\t'Cannot access event.url.hash. Consider using `page.url.hash` inside a component instead'\n\t\t\t);\n\t\t}\n\t});\n}\n\n/**\n * Disallow access to `url.search` and `url.searchParams` during prerendering\n * @param {URL} url\n */\nexport function disable_search(url) {\n\tallow_nodejs_console_log(url);\n\n\tfor (const property of ['search', 'searchParams']) {\n\t\tObject.defineProperty(url, property, {\n\t\t\tget() {\n\t\t\t\tthrow new Error(`Cannot access url.${property} on a page with prerendering enabled`);\n\t\t\t}\n\t\t});\n\t}\n}\n\n/**\n * Allow URL to be console logged, bypassing disabled properties.\n * @param {URL} url\n */\nfunction allow_nodejs_console_log(url) {\n\tif (!BROWSER) {\n\t\t// @ts-ignore\n\t\turl[Symbol.for('nodejs.util.inspect.custom')] = (_depth, opts, inspect) => {\n\t\t\treturn inspect(new URL(url), opts);\n\t\t};\n\t}\n}\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/utils/url.js#L186-L222","documentation":"@sveltejs/kit's `disable_search` replaces the `search` and `searchParams` accessors on the request URL with getters that always throw, so code cannot read the query string during prerendering. Prerendered pages must be identical for every visitor, so the query string is meaningless; the library throws to surface accidental reliance on it instead of silently producing wrong output.","triggerScenarios":"Accessing `url.search` or `url.searchParams` (directly or via helpers like `new URLSearchParams(url.search)`) inside load functions, page data, or handlers on a route being prerendered (`export const prerender = true` or global prerender config).","commonSituations":"Reading `?page=` or `?token=` from a URL in a prerendered page; calling `fetch(url)` with a URL object whose searchParams are read for cache-busting; sharing a load function between prerendered and dynamic routes without guarding query-string access.","solutions":["Remove any read of `url.search`/`url.searchParams` from code paths that run during prerendering.","Disable prerendering for routes that legitimately need the query string (`export const prerender = false`).","Use page.url only for non-query parts (origin, pathname) in prerendered pages.","Move query-string-dependent logic to client-side code or a server endpoint instead of the prerendered load."],"exampleFix":"// before (prerendered route)\nexport function load({ url }) {\n  const token = url.searchParams.get('token');\n  return { token };\n}\n\n// after: make the route dynamic\nexport const prerender = false;\nexport function load({ url }) {\n  const token = url.searchParams.get('token');\n  return { token };\n}","handlingStrategy":"validation","validationCode":"if (import.meta.env.SSR && should_prerender && (url.search || url.searchParams.size)) {\n  throw new Error('query string used in prerendered route');\n}","typeGuard":"function has_query(url) { return url.search.length > 0; }","tryCatchPattern":"try {\n  const q = url.searchParams.get('page');\n} catch {\n  const q = null; // prerendering: fall back to default\n}","preventionTips":["Never read query params in load functions of prerendered routes","Set `export const prerender = false` on query-dependent routes","Audit shared load helpers for url.search/searchParams usage","Use `url.pathname`/`origin` only in prerendered code"],"tags":["prerendering","url","query-string","ssg"],"backgroundTag":"query-string-access-during-prerender","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}