New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NuxtLink retains scroll position #14544
Comments
Did you check the app/router.option documentation ? You can change the scrollBehavior by creating a config file import type { RouterConfig } from '@nuxt/schema'
// https://router.vuejs.org/api/#routeroptions
export default <RouterConfig>{
scrollBehavior(to, from, savedPosition) {
// always scroll to top
return { top: 0 }
},
} Alternatively why not trying to create a plugin like a import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.$router.options.scrollBehavior = (to, from, savedPosition) => {
// always scroll to top
return { top: 0 }
}
}) |
Thanks @BenjaminOddou I will give it a try. However, the normal (globally accepted) response in a browser when clicking a link without a I should not have to configure anything to achieve the normally expected behaviour when navigating to a new resource. |
Would you provide a reproduction? 🙏 |
Hello, Using RC-6, I have the same issue. Go to https://le-classement.fr/, scroll to the first Repo is here: https://github.com/barbapapazes/le-classement.fr |
Here is a solution that checks for saved position and hashes, defaulting to scrolling to the top of the page.
import type { RouterConfig } from '@nuxt/schema'
// https://router.vuejs.org/api/#routeroptions
export default <RouterConfig> {
scrollBehavior(to, _from, savedPosition) {
return new Promise((resolve, _reject) => {
setTimeout(() => {
if (savedPosition) {
resolve(savedPosition)
} else {
if (to.hash) {
resolve({
el: to.hash,
top: 80
})
} else {
resolve({ top: 0 })
}
}
}, 100)
})
}
} You might not need the |
Thanks @jshimkoski - a useful bit of code. However, as already mentioned, we shouldn't have to write a hack for this. The default functionality when clicking a link to a new resource is to show the resource from the top. This is a bug in Nuxt rc 6. |
Not fixed! Still seeing this unexpected problem in rc8 |
Please attach a minimal reproduction (e.g. via CodeSandbox or StackBlitz) so it is easier to tackle the issue |
Here's a minimal project to demonstrate the issue @manniL https://github.com/chrisnoden/nuxt3-bug Here is a video of what happens: Capto_Capture.2022-08-16_05-18-29_pm.mov |
Reproduced in a minimal project above @danielroe |
@danielroe is this addressed in RC-9, RC-8 had the issue. |
It still happens for me in RC-9. And in combination with #14005 it's quite a faulty navigation experience atm.. |
Same here with RC-11 for information |
Let's track in #13284. |
Can confirm this issue still persist as of RC-12 |
It is resolved in the edge channel, or in the next RC. |
Can you confirm what exactly the resolution is? What's the default? What happens? |
I've updated to rc.13 and this bug is not resolved for me. |
@chrisnoden Please do raise a new issue with a reproduction. 🙏 |
done as #15356 🤞 |
Environment
Darwin
v16.15.1
3.0.0-rc.7
yarn@1.22.19
vite
build
,buildModules
,css
,googleFonts
,modules
,nitro
,runtimeConfig
@storyblok/nuxt@4.1.0
@nuxtjs/tailwindcss@5.3.1
,@nuxtjs/google-fonts@1.3.0
Reproduction
<NuxtLink :to="/page2">Link</NuxtLink>
Describe the bug
If you have reasonably long pages and common links near the bottom, clicking a link loads the target page content, but the scroll position no longer goes to the top of the new page.
Additional context
Reverting to
rc.6
reverts the behaviour to the expected "jump to top of new page".Logs
No response
The text was updated successfully, but these errors were encountered: