Scroll to top when new page loads
How do I make nuxt scroll to top every time new page is visited?
Right now I tried to make my own plugin but it doesn't work for some reason...
(It doesn't even console log)
scroll.js
28 Replies
Hi, are you trying to archive a scroll top everytime a user hits refresh? Or when clicking between routes with
<NuxtLink>
When clicking between routes. for example your scroll down in index and click on view more products that puts you on /products but like in the middle of the page
Nuxt 3 does that automatically, you don't have to add a plugin or so π
Is it disabled in dev?
Nope, works fine for my project. Which nuxt version do you use? And do you use
<NuxtLink />
for all your links?<NuxtLink/>
Nuxt 3
And it doesn't work for me
Even in buildInteresting. Can you share a bit of the code? Like where you implemented the link
And maybe a screen recording
Works for all my nuxt 3 projects
(dev version a lot of testing code)
this is the page if you want to have a look your self
this code is a component if you scroll down a bit
But what surprises me is that the hook is not even called like this is in the documentation so it should work regardless right?
Yeah that is strange. I can imagine that something is blocking this from happening. Can you show your
nuxt.config.ts
?
And do you have any vue router config in your app?
nope
looks fine
can you show your package.json
maybe the whole repo at this point would be easier if thats okay for you haha
Sorry I cannot do that even sharing the link and pieces of code are bit on the edge π
Understandable
but in package.json nothing strange just scripts and devDependencies nuxt "^3.1.0"
Can you try to delete the whole .nuxt and .output and node_modules and package-lock.json and
npm i nuxt@latest
Have to go for nowUnknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
how?
@Sr. Full Stack Dev normally not needed since this is something working in a regular nuxt project. So if @qb1t would create a brand new nuxt project right now, it would work. Therefore trying to find out what happens in your project that prevents this.
I've created this project like 4 days ago so don't know what went wrong
Yeah itβs pretty strange. Maybe Try to create an new one, add some long texts into two pages and link them to check whether itβs working in.
And try to add #
scroll-behaviour: smooth;
in your html {} css styles.
Check out http://wordpress-madebyfabian.vercel.app my current nuxt project itβs working perfectly fine for me
If you want to I can give you access to the GitHub repo to check my code
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
I have posted a bunch of stuff here now guys, please try that out @Wesley
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
I tagged this post as
["solved", "answered", "bug"]
because the last solution worked for me, so solved and answered but the thing should have worked automatically so also bugstill weired
but when you have a long site
and you go to a page the new should start on top but when you go back
it should use the old state for the page you go back?