@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
52 lines (51 loc) • 1.57 kB
JavaScript
import { useRouter } from "./useRouter.js";
import { Asset } from "./Asset.js";
import { _getAssetMatches, replaceEqualDeep } from "@tanstack/router-core";
import { createComponent } from "solid-js/web";
import * as Solid from "solid-js";
import { isServer } from "@tanstack/router-core/isServer";
//#region src/Scripts.tsx
var Scripts = () => {
const router = useRouter();
const nonce = router.options.ssr?.nonce;
const scripts = Solid.createMemo((previous) => {
const matches = _getAssetMatches(router.stores.matches.get());
const next = [];
const assets = [];
const manifest = router.ssr?.manifest;
for (const match of matches) {
for (const script of match.scripts ?? []) {
if (!script) continue;
const { children, ...attrs } = script;
next.push({
tag: "script",
attrs: {
...attrs,
nonce
},
children
});
}
for (const asset of manifest?.routes[match.routeId]?.scripts ?? []) assets.push({
tag: "script",
attrs: {
...asset.attrs,
nonce
},
children: asset.children
});
}
next.push(...assets);
return previous ? replaceEqualDeep(previous, next) : next;
});
const serverBufferedScript = (isServer ?? router.isServer) && router.serverSsr ? router.serverSsr.takeBufferedScripts() : void 0;
return [serverBufferedScript && createComponent(Asset, serverBufferedScript), createComponent(Solid.For, {
get each() {
return scripts();
},
children: (asset) => createComponent(Asset, asset)
})];
};
//#endregion
export { Scripts };
//# sourceMappingURL=Scripts.js.map