Restores scroll position when navigating back and forth in NextJS
npm install next-restore-scroll-positionRestores scroll position when navigating back and forth in NextJS.
```
yarn add next-restore-scroll-position
``
npm i next-restore-scroll-position
js
import { useScrollRestoration } from 'next-restore-scroll-position';function App() { // This needs to be NextJS App Component
const router = useRouter();
useScrollRestoration(router);
}
`You can also disable the scroll restoration by passing
enabled property`js
import { useScrollRestoration } from 'next-restore-scroll-position';function App() { // This needs to be NextJS App Component
const router = useRouter();
useScrollRestoration(router, {enabled: false});
}
``- React 16 or up
- Next 13