Skip to content

pushState/replaceState don't trigger beforeNavigate #11776

@samal-rasmussen

Description

@samal-rasmussen

Describe the bug

I just started using pushState/replaceState and realized that they don't trigger beforeNavigate, and so I cannot ask the user to confirm before navigating away from a modal form.

I have a rather big webapp that will need to have complex forms in modals. Users definitely want to be asked for confirmation before losing complex form state.

Reproduction

This modal will ask for confirmation when clicking the cancel button, but not on pressing back in the browser:
https://stackblitz.com/edit/sveltejs-kit-template-default-fsoasb?file=src%2Froutes%2FModal.svelte

There's a beforeNavigate that should be showing the confirmation, but it isn't called.

Logs

No response

System Info

Forked the newest Sveltekit Stackblitz.

Severity

Serious. My users can lose some large amounts of state when navigating away from a dirty form.

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions