20 lines
506 B
TypeScript
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;
|
|
}
|
|
});
|
|
});
|