Access the location object of a memory router for testing purposes #11200
Closed
silvenon
started this conversation in
Show and tell / tips
Replies: 1 comment 4 replies
-
yeah, |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wasn't able to find this in the docs, so I managed to find it in the source code. I was writing unit tests using
createMemoryRouter
and wanted to check whether expected search params have been added. I noticed that I can reach the router's location object through router'sstate
property:Usually you'd want to test the impact of your search params, rather than the params themselves, but in my case I wanted to check one of the search params just to be sure.
Let me know if there is a better way to do this, and whether accessing the
state
property is fine. Until then, this works 💯EDIT: To avoid using the low-level
state
property, a good alternative is to useuseLocation()
in a pathless layout route: #11200 (reply in thread)Beta Was this translation helpful? Give feedback.
All reactions