T
TanStack•9mo ago
rare-sapphire

How to detect page navigation and i.e. close mobile menu?

I have full-screen mobile menu with Links and I'd like to close it on-navigate. What's the proper way to handle it?
4 Replies
xenial-black
xenial-black•9mo ago
can you provide more details?
rare-sapphire
rare-sapphireOP•9mo ago
So usually, mobile menu closes when you clicks the link. Of course, I could probably use onClick() to handle that, but I'm not sure wheter it's the best practice here. Instead, I'd like to detect that the navigating process started, and then use this info to hide/close the mobile menu automatically, so it won't annoy the users I know there is something like: router.history.subscribe(), but this would require some global state I guess I hope there is some better solution as it's pretty common case
xenial-black
xenial-black•9mo ago
yeah why not onClick? it's exactly what you want
rare-sapphire
rare-sapphireOP•9mo ago
Well, looks like I always overcomplicate things 😅 onClick is good enough. Thanks

Did you find this page helpful?