sveltejs/kit · error
Attempted to preload a URL that does not belong to this app:
Error message
Attempted to preload a URL that does not belong to this app: ${url} What it means
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.
Source
Thrown at packages/kit/src/runtime/client/client.js:2801
/**
* Programmatically preloads the given page, which means
* 1. ensuring that the code for the page is loaded, and
* 2. calling the page's load function with the appropriate options.
*
* This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.
* If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
* Returns a Promise that resolves with the result of running the new route's `load` functions once the preload is complete.
*
* @param {string} href Page to preload
* @returns {Promise<({ type: 'loaded'; data: Record<string, any> } | { type: 'redirect'; location: string } | { type: 'error'; error: App.Error }) & { status: number; }>}
*/
export async function preloadData(href) {
const url = resolve_url(href);
const intent = await get_navigation_intent(url, false);
if (!intent) {
throw new Error(`Attempted to preload a URL that does not belong to this app: ${url}`);
}
/** @type {Awaited<ReturnType<typeof _preload_data>>} */
let result;
try {
result = await _preload_data(intent);
} catch (error) {
// `load_route` throws the handled error (an `App.Error` with a `status`)
// when a preload fails, so surface it in the documented `{ type: 'error' }` shape
const handled = /** @type {App.Error & { status?: number }} */ (error);
return {
type: 'error',
status: handled?.status ?? 500,
error: handled
};
}
View on GitHub (pinned to 03f1687fe6)
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)
Example fix
// before
link.addEventListener('mouseenter', () => preloadData(link.href));
// after
link.addEventListener('mouseenter', () => {
const u = new URL(link.href, location.href);
if (u.origin === location.origin) preloadData(u.pathname).catch(() => {});
}); Defensive patterns
Strategy: try-catch
Validate before calling
function canPreload(href) {
const u = new URL(href, location.href);
return u.origin === location.origin && !u.pathname.startsWith('/api/');
} Try / catch
try { await preloadData(href); } catch { /* not an app route; skip */ } Prevention
- Filter external links before prefetching on hover/viewport
- Only preload hrefs generated from your own route table
- Treat preload failures as non-fatal optimizations
When it happens
Trigger: 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.
Common situations: Custom link-hover prefetch utilities that don't filter external/route-less URLs; dynamic URLs built from CMS content pointing outside the app.
Related errors
- Files prefixed with + are reserved (saw ${project_relative})
- Only Svelte files can reference named layouts. Remove '${mat
- Files and directories prefixed with + are reserved (saw ${pr
- Invalid route ID ${id}
- Invalid param definition
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/25063532968dd357.
Report an issue: GitHub.