landing scroll top fix

pull/3455/head
Tuğçe Küçükoğlu 2022-12-28 12:32:27 +03:00
parent cfd26964d7
commit 015c54cc48
2 changed files with 9 additions and 23 deletions

View File

@ -0,0 +1,9 @@
export default defineNuxtRouteMiddleware((to, from) => {
useNuxtApp().hook('page:finish', () => {
if (to.path !== from.path && history.state.scroll) {
setTimeout(() => window.scrollTo(history.state.scroll), 0);
} else {
setTimeout(() => window.scrollTo(0, 0), 0);
}
});
});

View File

@ -1,23 +0,0 @@
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.$router.options.scrollBehavior = async (to, from, savedPosition) => {
let goTo;
if (to.hash) {
console.log(to);
goTo = {
el: to.hash,
top: 0
};
} else if (savedPosition) {
goTo = savedPosition;
} else {
goTo = { top: 0 };
}
return new Promise((resolve) => {
setTimeout(() => {
resolve(goTo);
}, 100);
});
};
});