Skip to content

useBeforeLeave not firing on history.back() #277

@KamehamehaNudel

Description

@KamehamehaNudel

Describe the bug

The "useBeforeLeave" hook seems to only be firing when navigating using links.
When using the browsers back/forth buttons it does not appear to execute.

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-ejhtft?file=src%2FApp.jsx

Steps to Reproduce the Bug or Issue

  1. Go to the "test" route using the nav link.
  2. Go back to the "home" routeusing the nav link.
  3. An alert "here" will show up
  4. Go back to the "test" route using the nav link.
  5. Click the "back" button (fires history.back())
  6. The route changes correctly, but the alert does not show up

Expected behavior

As a user i expeted the "useBeforeLeave" function to also fire when using the "back" button (either progromatically or with the actual browser buttons in a 'real' environment).
I am in both cases leaving the current route so I don't see why it shouln't execute.

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Firefox
  • Version: 114.0.2 (64-Bit)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions