UNPKG

@tanstack/solid-router

Version:

Modern and scalable routing for Solid applications

34 lines (33 loc) 1.4 kB
const require_runtime = require("./_virtual/_rolldown/runtime.cjs"); const require_useRouter = require("./useRouter.cjs"); const require_matchContext = require("./matchContext.cjs"); let _tanstack_router_core = require("@tanstack/router-core"); let solid_js = require("solid-js"); solid_js = require_runtime.__toESM(solid_js, 1); //#region src/useMatch.tsx function useMatch(opts) { const router = require_useRouter.useRouter(); const contextMatch = solid_js.useContext(require_matchContext.nearestMatchContext); const nearestMatch = opts.from ? void 0 : contextMatch; const match = () => { if (opts.from) return router.stores.getMatchStore(opts.from).get(); return nearestMatch?.[1](); }; solid_js.createEffect(() => { if (match() !== void 0) return; if (opts.shouldThrow ?? true) { if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`); (0, _tanstack_router_core.invariant)(); } }); return solid_js.createMemo((prev) => { const selectedMatch = match(); if (selectedMatch === void 0) return; const res = opts.select ? opts.select(selectedMatch) : selectedMatch; if (prev === void 0) return res; return (0, _tanstack_router_core.replaceEqualDeep)(prev, res); }); } //#endregion exports.useMatch = useMatch; //# sourceMappingURL=useMatch.cjs.map