@tanstack/vue-router
Version:
Modern and scalable routing for Vue applications
51 lines (50 loc) • 1.53 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;
const transition = async (fn) => {
fn();
await Vue.nextTick();
return true;
};
router.startTransition = transition;
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