2024-05-01 10:40:33 +02:00
|
|
|
<template>
|
|
|
|
|
<slot />
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-06-21 07:12:04 +02:00
|
|
|
const root = useParentElement(useParentElement());
|
2024-05-01 10:40:33 +02:00
|
|
|
// Store and keep y to restore it on page change
|
|
|
|
|
const route = useRoute();
|
2024-06-21 07:12:04 +02:00
|
|
|
const yStored = useLocalStorage("lysand:scroll", {
|
|
|
|
|
[route.fullPath]: 0,
|
|
|
|
|
});
|
2024-05-01 10:40:33 +02:00
|
|
|
const { y } = useScroll(root);
|
|
|
|
|
|
|
|
|
|
useEventListener("popstate", async (event) => {
|
2024-06-21 07:12:04 +02:00
|
|
|
if (yStored.value[route.fullPath] !== undefined) {
|
2024-05-01 10:40:33 +02:00
|
|
|
// Wait for the Vue component to load
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
2024-06-21 07:12:04 +02:00
|
|
|
y.value = yStored.value[route.fullPath] ?? 0;
|
2024-05-01 10:40:33 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onBeforeRouteLeave(() => {
|
2024-06-21 07:12:04 +02:00
|
|
|
yStored.value[route.fullPath] = y.value;
|
|
|
|
|
yStored.value = { ...yStored.value };
|
2024-05-01 10:40:33 +02:00
|
|
|
});
|
|
|
|
|
</script>
|