import type { Vue } from 'vue-facing-decorator'; import { globalState } from '../app/global-state'; import PowerduckState from '../app/powerduck-state'; type VueType = typeof Vue.prototype; export const setCurrentUrl = (instance: VueType, url: string) => { const newUrl = new URL(url, globalState.location.origin); const currentUrl = new URL(globalState.location.href); const router = PowerduckState.getRouter(); const route = PowerduckState.getCurrentRouteQuery(); if (!router || !route) { return; } let nextTick = instance?.$nextTick; if (nextTick == null) { nextTick = (cb) => { cb(); }; } if (currentUrl.href != newUrl.href) { const path = newUrl.pathname + newUrl.search + newUrl.hash; if (route.fullPath !== path) { router.replace(path); } nextTick(() => { if (route.fullPath !== path) { router.replace(path); } }); setTimeout(() => { if (route.fullPath !== path) { router.replace(path); } }, 500); } };