@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
43 lines (42 loc) • 1.49 kB
JavaScript
import { useRouter } from "./useRouter.js";
import { Asset } from "./Asset.js";
import { createComponent, memo } from "solid-js/web";
import * as Solid from "solid-js";
//#region src/Scripts.tsx
var Scripts = () => {
const router = useRouter();
const nonce = router.options.ssr?.nonce;
const activeMatches = Solid.createMemo(() => router.stores.activeMatchesSnapshot.state);
const assetScripts = Solid.createMemo(() => {
const assetScripts = [];
const manifest = router.ssr?.manifest;
if (!manifest) return [];
activeMatches().map((match) => router.looseRoutesById[match.routeId]).forEach((route) => manifest.routes[route.id]?.assets?.filter((d) => d.tag === "script").forEach((asset) => {
assetScripts.push({
tag: "script",
attrs: {
...asset.attrs,
nonce
},
children: asset.children
});
}));
return assetScripts;
});
const scripts = Solid.createMemo(() => activeMatches().map((match) => match.scripts).flat(1).filter(Boolean).map(({ children, ...script }) => ({
tag: "script",
attrs: {
...script,
nonce
},
children
})));
let serverBufferedScript = void 0;
if (router.serverSsr) serverBufferedScript = router.serverSsr.takeBufferedScripts();
const allScripts = [...scripts(), ...assetScripts()];
if (serverBufferedScript) allScripts.unshift(serverBufferedScript);
return memo(() => allScripts.map((asset, i) => createComponent(Asset, asset)));
};
//#endregion
export { Scripts };
//# sourceMappingURL=Scripts.js.map