#scroll restoration

1 messages ยท Page 1 of 1 (latest)

clever marsh
#

Instead of adding this to _app.js, I would add this to the catalogue page

#

since you only want it for that page

green briar
#

oh

#

let me try that

clever marsh
#

What Im doing inside the page I want the scroll restoration is just this

const updateScroll = useRouterScroll()?.updateScroll;

  useEffect(() => {
    if (updateScroll) {
      updateScroll();
    }
  }, [updateScroll]);

and works fine for me ^^ (edit: I find this easier that shouldUpdateScroll )

green briar
#

yeah but then I have to apply that to each page (except catalogue)

#

wouldn't be a bit redundant like that?

#

or it's ok ?

clever marsh
#

Didnt you say you only want it for one page? If its multiple pages then yea its better to use shouldUpdateScroll

green briar
#

oh wait

#

you mean use it on catalogue?

clever marsh
#

yes

green briar
#

ah ok

#

it's working %50

#

sometimes not working

#

sometimes working

clever marsh
#

Hard to tell without knowing more about the project. Is there any case where you might want to rerun updateScroll maybe? ๐Ÿค”

#

you can also look at the SessionStorage on your dev tools to see the values of the scroll positions

green briar
#

localStorage worked easier ๐Ÿ˜„

#

I think I should just use that