[Bug]: window.location
is not updated after a call to router.navigate()
#11487
Labels
window.location
is not updated after a call to router.navigate()
#11487
What version of React Router are you using?
^6.23.0
Steps to Reproduce
When using React Router in a test suite, I'm observing that
window.location
does not get updated when a call torouter.navigate()
is made.I'm trying to test a custom hook who's return value is dependent on the current state of the URL. For performance purposes, we're getting the current location of the app from
window.location
, rather than throughuseLocation()
(we have a separate, but similar, hook that calls this).The setup in the tests is the following:
vitest
router
is the result of callingcreateMemoryRouter()
with an array ofRouteObject
's, which is then given to the<RouterProvider />
in thewrapper
key ofrendeHook()
accordingly.initialProps
for the hook that I'm testingrouter.navigate()
, called inside anact()
statementWhat I'm seeing, at the point when I call
rerender()
afterrouter.navigate()
has updated the URL, is that the value ofuseLocation().pathname
is not equal to the value ofwindow.location.pathname
.useLocation()
is set to the value thatrouter.navigate()
just defined, butwindow.location
is being left behind.For what it's worth, this seems to be the opposite of #11473
Expected Behavior
window.location.pathname === useLocation().pathname
afterrouter.navigate()
is calledActual Behavior
window.location
is still set to the previous location whereasuseLocation
is updated correctlyThe text was updated successfully, but these errors were encountered: