Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unable to Pass State Using useNavigate When Navigating Back to Previous Route #11392

Closed
Sen-442b opened this issue Apr 2, 2024 · 1 comment
Labels

Comments

@Sen-442b
Copy link

Sen-442b commented Apr 2, 2024

What version of React Router are you using?

"^6.14.2"

Steps to Reproduce

  • Navigate to this sandbox.
  • Click on the "New Route" button to navigate to "/new-route".
  • On the "/new-route" page, attempt to navigate back to the home route by clicking the "Go Back" button.
  • The navigation back to the home route occurs, but the state passed during the navigation is not accessible in the home route.

Expected Behavior

Upon clicking the "Go Back" button, the application should navigate back to the home route, and the state passed during the navigation should be accessible in the home (redirected) route.

Actual Behavior

The navigation back to the home route occurs, but the state passed during the navigation is not accessible in the home route.

navigate(-1, { state: { message: 'message from new route' } }) //the message does not carry over to the redirected route.

@Sen-442b Sen-442b added the bug label Apr 2, 2024
@timdorr
Copy link
Member

timdorr commented Apr 2, 2024

This is expected behavior. The previous location is immutable. You cannot modify it by adding new state when navigating backwards. If you need to add state, you have a new location and need to navigate forwards. This is the same behavior as the native back() function.

@timdorr timdorr closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants