MCPcopy
hub / github.com/sveltejs/kit / preloadData

Function preloadData

packages/kit/src/runtime/client/client.js:2067–2089  ·  view source on GitHub ↗
(href)

Source from the content-addressed store, hash-verified

2065 * @returns {Promise<{ type: 'loaded'; status: number; data: Record<string, any> } | { type: 'redirect'; location: string }>}
2066 */
2067export async function preloadData(href) {
2068 if (!BROWSER) {
2069 throw new Error('Cannot call preloadData(...) on the server');
2070 }
2071
2072 const url = resolve_url(href);
2073 const intent = await get_navigation_intent(url, false);
2074
2075 if (!intent) {
2076 throw new Error(`Attempted to preload a URL that does not belong to this app: ${url}`);
2077 }
2078
2079 const result = await _preload_data(intent);
2080 if (result.type === 'redirect') {
2081 return {
2082 type: result.type,
2083 location: result.location
2084 };
2085 }
2086
2087 const { status, data } = result.props.page ?? page;
2088 return { type: result.type, status, data };
2089}
2090
2091/**
2092 * Programmatically imports the code for routes that haven't yet been fetched.

Callers 1

utils.jsFile · 0.85

Calls 3

resolve_urlFunction · 0.90
get_navigation_intentFunction · 0.85
_preload_dataFunction · 0.85

Tested by

no test coverage detected