Skip to content

Cannot reset scroll in the popstate event #1818

@mx1700

Description

@mx1700

useEffect(() => {
const callback = () => {
const route = parseRoute(new URL(window.location.href));
changeRoute(route, { shouldScroll: true }).catch((err) => {
console.log('Error while navigating back:', err);
});
};
window.addEventListener('popstate', callback);
return () => {
window.removeEventListener('popstate', callback);
};
}, [changeRoute]);

If scroll is not reset here, the browser will automatically restore the scrolling position, which is in line with the general behavior of browsers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions