@tanstack/vue-router
Version:
Modern and scalable routing for Vue applications
52 lines (51 loc) • 1.58 kB
JavaScript
import { useRouter } from "./useRouter.js";
import { getLocationChangeInfo, trimPathRight } from "@tanstack/router-core";
import * as Vue from "vue";
import { isServer } from "@tanstack/router-core/isServer";
//#region src/Transitioner.tsx
function useTransitionerSetup() {
const router = useRouter();
if (isServer ?? router.isServer) return;
let transitionOwner;
router.startTransition = async (fn, expected) => {
transitionOwner = expected;
fn();
await Vue.nextTick();
return transitionOwner === expected;
};
Vue.onMounted(() => {
Vue.onUnmounted(router.history.subscribe(router.load));
const nextLocation = router.buildLocation({
to: router.latestLocation.pathname,
search: true,
params: true,
hash: true,
state: true,
_includeValidateSearch: true
});
if (trimPathRight(router.latestLocation.publicHref) !== trimPathRight(nextLocation.publicHref)) {
router.commitLocation({
...nextLocation,
replace: true,
ignoreBlocker: true
});
return;
}
const resolvedLocation = router.stores.resolvedLocation.get();
if (resolvedLocation?.href === router.latestLocation.href && resolvedLocation.state.__TSR_key === router.latestLocation.state.__TSR_key) router.emit({
type: "onRendered",
...getLocationChangeInfo(resolvedLocation, resolvedLocation)
});
else if (!router._tx) router.load().catch(console.error);
});
}
Vue.defineComponent({
name: "Transitioner",
setup() {
useTransitionerSetup();
return () => null;
}
});
//#endregion
export { useTransitionerSetup };
//# sourceMappingURL=Transitioner.js.map