one
Version:
One is a React framework for web, iOS, and Android apps.
30 lines (27 loc) • 958 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