{"record":{"id":"25063532968dd357","repo":"sveltejs/kit","slug":"attempted-to-preload-a-url-that-does-not-belong-to","errorCode":null,"errorMessage":"Attempted to preload a URL that does not belong to this app: ${url}","messagePattern":"Attempted to preload a URL that does not belong to this app: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/client/client.js","lineNumber":2801,"sourceCode":"\n/**\n * Programmatically preloads the given page, which means\n *  1. ensuring that the code for the page is loaded, and\n *  2. calling the page's load function with the appropriate options.\n *\n * This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.\n * If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.\n * Returns a Promise that resolves with the result of running the new route's `load` functions once the preload is complete.\n *\n * @param {string} href Page to preload\n * @returns {Promise<({ type: 'loaded'; data: Record<string, any> } | { type: 'redirect'; location: string } | { type: 'error'; error: App.Error }) & { status: number; }>}\n */\nexport async function preloadData(href) {\n\tconst url = resolve_url(href);\n\tconst intent = await get_navigation_intent(url, false);\n\n\tif (!intent) {\n\t\tthrow new Error(`Attempted to preload a URL that does not belong to this app: ${url}`);\n\t}\n\n\t/** @type {Awaited<ReturnType<typeof _preload_data>>} */\n\tlet result;\n\n\ttry {\n\t\tresult = await _preload_data(intent);\n\t} catch (error) {\n\t\t// `load_route` throws the handled error (an `App.Error` with a `status`)\n\t\t// when a preload fails, so surface it in the documented `{ type: 'error' }` shape\n\t\tconst handled = /** @type {App.Error & { status?: number }} */ (error);\n\t\treturn {\n\t\t\ttype: 'error',\n\t\t\tstatus: handled?.status ?? 500,\n\t\t\terror: handled\n\t\t};\n\t}\n","sourceCodeStart":2783,"sourceCodeEnd":2819,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/client.js#L2783-L2819","documentation":"preloadData() resolves the href against the app's route table via get_navigation_intent(); if no route matches, the URL does not belong to the app and preloading cannot proceed, so it throws. Preloading is an optimization for in-app navigations only.","triggerScenarios":"preloadData('https://cdn.example.com/x.js') or preloadData('/path-without-route'); calling it from an <a> hover handler for external links; stale hrefs after route removal.","commonSituations":"Custom link-hover prefetch utilities that don't filter external/route-less URLs; dynamic URLs built from CMS content pointing outside the app.","solutions":["Only call preloadData for same-origin hrefs that match a route","Guard with a try/catch or route check before preloading","Filter external links out of your prefetch logic (check url.origin)"],"exampleFix":"// before\nlink.addEventListener('mouseenter', () => preloadData(link.href));\n// after\nlink.addEventListener('mouseenter', () => {\n  const u = new URL(link.href, location.href);\n  if (u.origin === location.origin) preloadData(u.pathname).catch(() => {});\n});","handlingStrategy":"try-catch","validationCode":"function canPreload(href) {\n  const u = new URL(href, location.href);\n  return u.origin === location.origin && !u.pathname.startsWith('/api/');\n}","typeGuard":null,"tryCatchPattern":"try { await preloadData(href); } catch { /* not an app route; skip */ }","preventionTips":["Filter external links before prefetching on hover/viewport","Only preload hrefs generated from your own route table","Treat preload failures as non-fatal optimizations"],"tags":["preload","routing","sveltekit"],"backgroundTag":"preload-outside-app-url","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}