diff --git a/composables/useAppHistory.js b/composables/useAppHistory.js index f586311..4204739 100644 --- a/composables/useAppHistory.js +++ b/composables/useAppHistory.js @@ -1,3 +1,6 @@ +let metaPosition = undefined; +let navigationDirection = 0; + export const useAppHistory = () => { const route = useRoute(); const router = useRouter(); @@ -10,6 +13,7 @@ export const useAppHistory = () => { currentUrl: route.fullPath, forwardUrl: null, position: null, + navigationDirection: 0, // And additionals get hasHistory() { @@ -26,18 +30,24 @@ export const useAppHistory = () => { }, }); - onBeforeMount(() => { + if (import.meta.client) { dataObject.ready = true; - + metaPosition ??= router.options.history.state.position; update(); - }); + } watch(() => route.fullPath, update); function update() { + if (metaPosition !== router.options.history.state.position) { + navigationDirection = Math.sign(router.options.history.state.position - metaPosition); + metaPosition = router.options.history.state.position; + } + dataObject.backUrl = router.options.history.state.back; dataObject.currentUrl = router.options.history.state.current; dataObject.forwardUrl = router.options.history.state.forward; dataObject.position = router.options.history.state.position; + dataObject.navigationDirection = navigationDirection; } return dataObject;