Why is useLocation's return object different from window.location? #8438
Replies: 1 comment
-
Apologies, this was supposed to be asked under the react-router repo. Here is the link for the same question, this time, under the appropriate repo 😅 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello team!
I'm wondering why the object returned from the useLocation hook has properties that differ from the
window.location
object, despite them having the same name, and me expecting that they would indeed refer to the same things. For example, assume the following URL:https://example.com/#/foo
When using react-router's HashRouter, I'd expect
reactRouterLocationObj.hash
to equalwindow.location.hash
, but this is not true since:reactRouterLocationObj.hash
->''
window.location.hash
->#/foo
I have a stackblitz demo to replicate if anyone wants to play around with it.
Any pointers to what I might be missing here?
Beta Was this translation helpful? Give feedback.
All reactions