UNPKG

vue-intlayer

Version:

Easily internationalize i18n your Vue applications with type-safe multilingual content management.

27 lines (26 loc) 1.19 kB
import { MessageKey as p } from "@intlayer/editor"; import { getCurrentInstance as w, onMounted as d, onBeforeUnmount as l } from "vue"; import { useCrossFrameState as u } from "./useCrossFrameState.mjs"; const m = (o, a) => u(p.INTLAYER_URL_CHANGE, o, a), E = (o) => { const [a, s] = m(o, { emit: !0, receive: !1 }), i = w(); let t, n; const e = () => s(window.location.pathname); return i ? (d(() => { t = history.pushState, n = history.replaceState; const r = (c) => (...h) => { c.apply(history, h), window.dispatchEvent(new Event("locationchange")); }; history.pushState = r(t), history.replaceState = r(n), window.addEventListener("locationchange", e), window.addEventListener("popstate", e), window.addEventListener("hashchange", e), e(); }), l(() => { window.removeEventListener("locationchange", e), window.removeEventListener("popstate", e), window.removeEventListener("hashchange", e), t && (history.pushState = t), n && (history.replaceState = n); })) : console.warn( "useCrossURLPathSetter must be called within a component setup function" ), [a, s]; }; export { E as useCrossURLPathSetter, m as useCrossURLPathState };