one
Version:
One is a new React Framework that makes Vite serve both native and web.
28 lines (27 loc) • 987 B
JavaScript
import { getPathnameFromFilePath } from "../utils/getPathnameFromFilePath.mjs";
import { findRouteNodeFromState } from "./findRouteNode.mjs";
function getRouteArtifactPaths(href, linking, rootNode) {
const fallback = {
loader: href,
preload: href
};
if (!linking?.getStateFromPath || !rootNode) return fallback;
const state = linking.getStateFromPath(href, linking.config);
const route = findRouteNodeFromState(state, rootNode);
if (!route) return fallback;
const pattern = getPathnameFromFilePath(route.contextKey.replace(/^\.\//, "/"));
if (route.type === "spa") {
const hasExplicitSpaMode = route.contextKey.split("/").some(segment => /\+spa(?:\.|$)/.test(segment));
const path = hasExplicitSpaMode ? pattern : href;
return {
loader: path,
preload: path
};
}
return {
loader: href,
preload: route.type === "ssg" ? href : pattern
};
}
export { getRouteArtifactPaths };
//# sourceMappingURL=getRouteArtifactPath.mjs.map