Skip to content

Commit

Permalink
fix: after loading 스크롤 복원 훅 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
borimong committed Aug 30, 2024
1 parent a973d6e commit bfb03d0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hooks/useScrollRestoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export default function useScrollRestoration() {
}

export const restoreScrollPosition = (router: NextRouter) => {
const scrollPos = JSON.parse(sessionStorage.getItem(router.asPath) || '{"x": 0, "y": 0}');
//const scrollPos = JSON.parse(sessionStorage.getItem(router.asPath) || '{"x": 0, "y": 0}');
const scrollPos = JSON.parse('{"x": 0, "y": 0}'); // router.asPath 가 기록된 경우, 페이지 재진입 시 scroll 이 아래쪽으로 기억되어 있는 문제가 발생

console.log(scrollPos);
window.scroll(scrollPos.x, scrollPos.y);
};

Expand Down

0 comments on commit bfb03d0

Please sign in to comment.