diff --git a/middleware/route.global.js b/middleware/route.global.js new file mode 100644 index 000000000..89c09ed84 --- /dev/null +++ b/middleware/route.global.js @@ -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); + } + }); +}); diff --git a/plugins/scrollToTop.js b/plugins/scrollToTop.js deleted file mode 100644 index e4977e4a3..000000000 --- a/plugins/scrollToTop.js +++ /dev/null @@ -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); - }); - }; -});