How to close navigation menu even when route didn't change?
Unanswered
White-tailed Tropicbird posted this in #help-forum
White-tailed TropicbirdOP
The most obvious way to close the navigation menu is to listen to
I thought of adding
How would you do it?
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
@White-tailed Tropicbird 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 `onClick`s to every link, but that feels very messy.
How would you do it?
there are two ways, you have described both. how else do you want to do it?
the second way may look messy but if you already have a component that wraps
next/link in your project it is doablei 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