Files
hossein-por-shop/frontend/plugins/scrollToTop.client.ts
T
2025-06-07 21:07:32 +03:30

20 lines
511 B
TypeScript

export default defineNuxtPlugin((nuxtApp) => {
let previousPath: string | null = null;
let isFirstLoad = true;
nuxtApp.hook("page:finish", () => {
const { fullPath: currentPath } = useRoute();
if (isFirstLoad) {
previousPath = currentPath;
isFirstLoad = false;
return;
}
if (previousPath !== currentPath) {
window.scrollTo({ top: 0, behavior: "auto" });
previousPath = currentPath;
}
});
});