Skip to content

Commit 5dbbcb0

Browse files
authored
fix scroll behaviour (#1131)
This change came up with #1128 and I put it in its own PR because #1130 also needs this This fix addresses several things: 1. scroll to the top of the page after following an internal page link 2. making on-page anchor-links (#) work specified with vue router-link https://phabricator.wikimedia.org/T408254 https://phabricator.wikimedia.org/T420575
1 parent 5a97304 commit 5dbbcb0

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/router/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ const router = new Router({
142142
},
143143
},
144144
],
145+
scrollBehavior (to, from, savedPosition) {
146+
// brings viewport back to where it was when using Back button
147+
if (savedPosition) return savedPosition
148+
149+
// scroll to in-page router-link anchor if used
150+
if (to.hash) {
151+
return { selector: to.hash, behavior: 'smooth' }
152+
}
153+
154+
// default: scroll to the top of the page
155+
return { x: 0, y: 0, behavior: 'smooth' }
156+
},
145157
})
146158

147159
// Require some routes to be logged in only.

0 commit comments

Comments
 (0)