mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-08 07:29:08 +03:00
Fix prefetching by checking if a route is prefetchable based on the how the URL resolves.
Uses https://developer.mozilla.org/en-US/docs/Web/API/URL/URL.
This commit is contained in:
parent
cafb9846a5
commit
e10c062267
4
index.js
4
index.js
@ -56,7 +56,7 @@ function loadContentAndInitializeApp(/** @type { init: any } */ mainElmModule)
|
||||
]
|
||||
});
|
||||
|
||||
window.allRoutes = fromElm.allRoutes;
|
||||
window.allRoutes = fromElm.allRoutes.map(route => new URL(route, document.baseURI).href);
|
||||
|
||||
if (navigator.userAgent.indexOf("Headless") >= 0) {
|
||||
fromElm.head.forEach(headTag => {
|
||||
@ -150,8 +150,8 @@ function prefetchIfNeeded(/** @type {HTMLAnchorElement} */ target) {
|
||||
if (target.host === window.location.host) {
|
||||
if (prefetchedPages.includes(target.pathname)) {
|
||||
// console.log("Already preloaded", target.href);
|
||||
} else if (!allRoutes.includes(target.pathname)) {
|
||||
// console.log("Not a known route, skipping preload", target.pathname);
|
||||
} else if (!allRoutes.includes(new URL(target.pathname, document.baseURI).href)) {
|
||||
}
|
||||
else {
|
||||
prefetchedPages.push(target.pathname);
|
||||
|
Loading…
Reference in New Issue
Block a user