(path, { priority } = {})
| 344 | } |
| 345 | |
| 346 | export async function prefetchTemplate(path, { priority } = {}) { |
| 347 | // Clean the path |
| 348 | path = getRoutePath(path) |
| 349 | // Get route info so we can check if path has any data |
| 350 | const routeInfo = await getRouteInfo(path, { priority }) |
| 351 | |
| 352 | if (routeInfo) { |
| 353 | // Make sure to use the path as defined in the routeInfo object here. |
| 354 | // This will make sure 404 route info returned from getRouteInfo is handled correctly. |
| 355 | registerTemplateForPath(routeInfo.path, routeInfo.template) |
| 356 | } |
| 357 | |
| 358 | // Preload the template if available |
| 359 | const Template = templatesByPath[path] |
| 360 | if (!Template) { |
| 361 | // If no template was found, mark it with an error |
| 362 | templateErrorByPath[path] = true |
| 363 | return |
| 364 | } |
| 365 | |
| 366 | // If we didn't no route info was return, there is nothing more to do here |
| 367 | if (!routeInfo) { |
| 368 | return Template |
| 369 | } |
| 370 | |
| 371 | if (!routeInfo.templateLoaded && Template.preload) { |
| 372 | if (priority) { |
| 373 | await Template.preload() |
| 374 | } else { |
| 375 | await requestPool.add(() => Template.preload()) |
| 376 | } |
| 377 | routeInfo.templateLoaded = true |
| 378 | } |
| 379 | return Template |
| 380 | } |
| 381 | |
| 382 | export async function prefetch(path, options = {}) { |
| 383 | // Clean the path |
no test coverage detected
searching dependent graphs…