added first loading check for scroll top
This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user