Browse Source

refactor(nc-gui): move shared-view postMessage into onMounted

pull/3810/head
Denis 2 years ago
parent
commit
ac0276f002
  1. 36
      packages/nc-gui/layouts/shared-view.vue

36
packages/nc-gui/layouts/shared-view.vue

@ -1,26 +1,28 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useRouter } from 'vue-router' import { navigateTo, useEventListener, useRouter } from '#imports'
import { navigateTo } from '#app'
const { isLoading, currentVersion } = useGlobal() const { isLoading, currentVersion } = useGlobal()
const { sharedView } = useSharedView() const { sharedView } = useSharedView()
const router = useRouter() const router = useRouter()
if (window.parent !== window) { onMounted(() => {
const notifyLocationChange = (value: string) => // check if we are inside an iframe
window.parent.postMessage( if (window.parent !== window) {
{ const notifyLocationChange = (value: string) =>
event: 'locationchange', window.parent.postMessage(
payload: { value }, {
}, event: 'locationchange',
'*', payload: { value },
) },
'*',
)
router.afterEach((to) => notifyLocationChange(location.origin + to.fullPath)) router.afterEach((to) => notifyLocationChange(location.origin + to.fullPath))
window.addEventListener('beforeunload', () => { useEventListener(window, 'beforeunload', () => {
const { href } = document.activeElement as { href?: string } const { href } = document.activeElement as { href?: string }
if (href) notifyLocationChange(href) if (href) notifyLocationChange(href)
}) })
} }
})
</script> </script>
<script lang="ts"> <script lang="ts">

Loading…
Cancel
Save