UNPKG

@tanstack/solid-router

Version:

Modern and scalable routing for Solid applications

63 lines (62 loc) 2.11 kB
const require_runtime = require("./_virtual/_rolldown/runtime.cjs"); const require_useRouter = require("./useRouter.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/Transitioner.tsx function getResolvedLocation(router) { const resolvedLocation = router.stores.resolvedLocation.get(); if (resolvedLocation?.href === router.latestLocation.href && resolvedLocation.state.__TSR_key === router.latestLocation.state.__TSR_key) return resolvedLocation; } function Transitioner() { const router = require_useRouter.useRouter(); router.startTransition = async (fn) => { const result = solid_js.runWithOwner(null, fn); try { solid_js.flush(); } catch {} await result; await new Promise((resolve) => queueMicrotask(resolve)); return true; }; solid_js.onSettled(() => { const unsub = router.history.subscribe(() => { queueMicrotask(() => router.load().catch(console.error)); }); router.updateLatestLocation(); const nextLocation = router.buildLocation({ to: router.latestLocation.pathname, search: true, params: true, hash: true, state: true, _includeValidateSearch: true }); if ((0, _tanstack_router_core.trimPathRight)(router.latestLocation.publicHref) !== (0, _tanstack_router_core.trimPathRight)(nextLocation.publicHref)) { router.commitLocation({ ...nextLocation, replace: true, ignoreBlocker: true }); return unsub; } if (!getResolvedLocation(router) && !router._tx) queueMicrotask(() => router.load().catch(console.error)); return unsub; }); return null; } function Rendered() { const router = require_useRouter.useRouter(); solid_js.onSettled(() => { const resolvedLocation = getResolvedLocation(router); if (resolvedLocation) router.emit({ type: "onRendered", ...(0, _tanstack_router_core.getLocationChangeInfo)(resolvedLocation, resolvedLocation) }); }); return null; } //#endregion exports.Rendered = Rendered; exports.Transitioner = Transitioner; //# sourceMappingURL=Transitioner.cjs.map