Files
hossein-por-shop/frontend/plugins/scrollToTop.client.ts
T
2025-06-04 19:14:22 +03:30

20 lines
506 B
TypeScript

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({ top: 0, behavior: "auto" });
previousPath = currentPath;
}
});
});