Next.js Discord

Discord Forum

How to close navigation menu even when route didn't change?

Unanswered
White-tailed Tropicbird posted this in #help-forum
Open in Discord
White-tailed TropicbirdOP
The most obvious way to close the navigation menu is to listen to usePathname() changes using a useEffect(), but I would like to also close the navigation menu when the user clicks on a link of a route that they're already on.
I thought of adding onClicks to every link, but that feels very messy.
How would you do it?

5 Replies

the second way may look messy but if you already have a component that wraps next/link in your project it is doable
i use the first way personally
@joulev i use the first way personally
White-tailed TropicbirdOP
Isn't it confusing for the user that they click something and nothing happens?
@White-tailed Tropicbird Isn't it confusing for the user that they click something and nothing happens?
i use a nprogress or something similar to visually indicate a route change is in progress