When the route changes, I need to locate the element with scrolling functionality on the new page and scroll it to the top using window.scrollTo(0,0). How can I achieve this?
Here is my current code snippet:
if (process.client) {
router.afterEach((to, from) => {
document.querySelector('.overflow-scroll').scrollTo(0, 0)
})
}
Although this code works fine, I would prefer not to use document.querySelector. Is there a way to dynamically find the scrolling element when the route changes?