(href)
| 2065 | * @returns {Promise<{ type: 'loaded'; status: number; data: Record<string, any> } | { type: 'redirect'; location: string }>} |
| 2066 | */ |
| 2067 | export 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. |
no test coverage detected