Skip to content

useLocation().state does not get updated on history back #396

Closed

Description

@r-Larch

Describe the bug

When navigating to a route with state object the route correctly sees the state but when navigating back the location.state will not update.

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-o9qpzf?file=src%2Findex.tsx

Steps to Reproduce the Bug or Issue

When navigating to a route with state object the route correctly sees the state but when navigating back the location.state will not update.

// having a component on route '/' with:
const location = useLocation();
createEffect(() => {
  console.log(location.state)
})

// doing with a button click:
// 1. navigate to:
navigate('/', { state: { foo: 'bar' } }); //   console: { foo: 'bar' }
// 2. navigate to:
navigate('/', { state: { foo: 'baz' } }); //   console: { foo: 'baz' }
// 3. navigate back:
history.back(); //   console: <no change> !! expected { foo: 'bar' }

Demo Reproduction: https://stackblitz.com/edit/solidjs-templates-o9qpzf?file=src%2Findex.tsx

Expected behavior

useLocation().state should reflect history.state and should reactively update.

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Chrome
  • Version: "^0.13.1"

Additional context

No response

Activity

  1. r-Larch commented on Mar 28, 2024

    @r-Larch
    Author
  2. added a commit that references this issue on Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions