mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix(vue-app): fix regression with scrollToTop
(#7920)
This commit is contained in:
parent
b487c7deb9
commit
9f4d420b1f
@ -22,21 +22,19 @@ if (process.client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function (to, from, savedPosition) {
|
export default function (to, from, savedPosition) {
|
||||||
// if the returned position is falsy or an empty object,
|
// If the returned position is falsy or an empty object, will retain current scroll position
|
||||||
// will retain current scroll position.
|
|
||||||
let position = false
|
let position = false
|
||||||
|
|
||||||
// if no children detected and scrollToTop is not explicitly disabled
|
|
||||||
const Pages = getMatchedComponents(to)
|
const Pages = getMatchedComponents(to)
|
||||||
|
|
||||||
|
// Scroll to the top of the page if...
|
||||||
if (
|
if (
|
||||||
Pages.length < 2 &&
|
// One of the children set `scrollToTop`
|
||||||
Pages.every(Page => Page.options.scrollToTop !== false)
|
Pages.some(Page => Page.options.scrollToTop) ||
|
||||||
|
// scrollToTop set in only page without children
|
||||||
|
(Pages.length < 2 && Pages.every(Page => Page.options.scrollToTop !== false))
|
||||||
) {
|
) {
|
||||||
// scroll to the top of the page
|
|
||||||
position = { x: 0, y: 0 }
|
|
||||||
} else if (Pages.some(Page => Page.options.scrollToTop)) {
|
|
||||||
// if one of the children has scrollToTop option set to true
|
|
||||||
position = { x: 0, y: 0 }
|
position = { x: 0, y: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,8 +45,12 @@ export default function (to, from, savedPosition) {
|
|||||||
|
|
||||||
const nuxt = window.<%= globals.nuxt %>
|
const nuxt = window.<%= globals.nuxt %>
|
||||||
|
|
||||||
// triggerScroll is only fired when a new component is loaded
|
if (
|
||||||
if (to.path === from.path && to.hash !== from.hash) {
|
// Route hash changes
|
||||||
|
(to.path === from.path && to.hash !== from.hash) ||
|
||||||
|
// Initial load (vuejs/vue-router#3199)
|
||||||
|
to === from
|
||||||
|
) {
|
||||||
nuxt.$nextTick(() => nuxt.$emit('triggerScroll'))
|
nuxt.$nextTick(() => nuxt.$emit('triggerScroll'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ describe('nuxt minimal vue-app bundle size limit', () => {
|
|||||||
it('should stay within the size limit range', async () => {
|
it('should stay within the size limit range', async () => {
|
||||||
const filter = filename => filename === 'vue-app.nuxt.js'
|
const filter = filename => filename === 'vue-app.nuxt.js'
|
||||||
const legacyResourcesSize = await getResourcesSize(distDir, 'client', { filter })
|
const legacyResourcesSize = await getResourcesSize(distDir, 'client', { filter })
|
||||||
const LEGACY_JS_RESOURCES_KB_SIZE = 16.5
|
const LEGACY_JS_RESOURCES_KB_SIZE = 16.6
|
||||||
expect(legacyResourcesSize.uncompressed).toBeWithinSize(LEGACY_JS_RESOURCES_KB_SIZE)
|
expect(legacyResourcesSize.uncompressed).toBeWithinSize(LEGACY_JS_RESOURCES_KB_SIZE)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user