added first loading check for scroll top

This commit is contained in:
Mamalizz
2025-06-04 19:14:22 +03:30
parent aaa0044ed6
commit fb6e026588
+8 -1
View File
@@ -1,11 +1,18 @@
export default defineNuxtPlugin((nuxtApp) => {
let previousPath: string | null = null;
let isFirstLoad = true;
nuxtApp.hook("page:finish", () => {
const currentPath = useRoute().fullPath;
if (isFirstLoad) {
previousPath = currentPath;
isFirstLoad = false;
return;
}
if (previousPath !== currentPath) {
window.scrollTo(0, 0);
window.scrollTo({ top: 0, behavior: "auto" });
previousPath = currentPath;
}
});