From 9262f6abfa14776ac7f26a32d8a541caee54e80e Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 2 Jun 2026 14:52:10 +0200 Subject: [PATCH] add scrollBehaviour handler --- src/router/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/router/index.js b/src/router/index.js index c164fc9d..9e8ea56b 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -142,6 +142,18 @@ const router = new Router({ }, }, ], + scrollBehavior (to, from, savedPosition) { + // brings viewport back to where it was when using Back button + if (savedPosition) return savedPosition + + // scroll to in-page router-link anchor if used + if (to.hash) { + return { selector: to.hash, behavior: 'smooth' } + } + + // default: scroll to the top of the page + return { x: 0, y: 0, behavior: 'smooth' } + }, }) // Require some routes to be logged in only.