nuxt: Inconsistent scrollToTop behaviour after update to 1.3.0
Certain pages that were (correctly) jumping to the top of the page after the route changed in 1.1.2 have stopped doing so in the latest release.
Steps to reproduce
- scroll down this page: http://next.btmat.org.uk/2012
- click on an article excerpt link
- see the article render half way down the page
Both the from page and the to page include scrollToTop: true.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 16
- Comments: 44 (6 by maintainers)
Commits related to this issue
- chore(examples): update scroll-behavior example (#4398) #2738 [skip release] — committed to nuxt/nuxt by manniL 6 years ago
This code does not run when a layout is changed. Think this is a bug.
i copy default(https://nuxtjs.org/api/configuration-router) to nuxt.config.js i found it ok nuxt1.4.0
router: { scrollBehavior: function (to, from, savedPosition) { if (savedPosition) { return savedPosition } else { let position = {} // 目标页面子组件少于两个 if (to.matched.length < 2) { // 滚动至页面顶部 position = { x: 0, y: 0 } } else if (to.matched.some((r) => r.components.default.options.scrollToTop)) { // 如果目标页面子组件中存在配置了scrollToTop为true position = { x: 0, y: 0 } } // 如果目标页面的url有锚点, 则滚动至锚点所在的位置 if (to.hash) { position = { selector: to.hash } } return position } } }Still an issue unfortunately, even on nuxt-edge. This is a pretty big bug IMO. Does anyone have a repo with multiple layouts where scroll to top works?
As far as I can see none of the suggested workarounds here allow for page transitions.
I have the same problem, in some route changes the scroll do not move to the top of the page.
The problem in that cases is the “triggerScroll” event in the scrollBehavior method of lib/app/router.js because the event was not triggered.
For now i am using this code in my nuxt.config.js file:
I’ve been using nuxt Edge and it is an issue usually
@sunlei4076 thanks for sharing. This version of
scrollBehaviorworked for me too.nuxt.config.js:As the majority of the problems of this mega-issue is solved, I’ll close hear and open a specific one for the problem related to the reproduction of @davidpmccormick
interesting, looks fixed for me
I spoke yesterday with @Atinux on this and the real issue is vue-router implementation here.
I think we should close / pause this and reference a bug on their side.
Using
:keyon top level element in the page component with dynamic routes fixes scrolling to top when route param changes.