themesberg / themesberg/flowbite-react
NavBar as={Link} (next/link; next.js) doesn't collapses the NavBar.Collapse
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.1k
- Forks
- 506
- PR merge metrics
- No merged PRs in 30d
Description
- I have searched the Issues to see if this bug has already been reported
- I have tested the latest version
Summary
When I do a
import Link from "next/link";
<Navbar.Collapse >
<Navbar.Link as={Link} active={pathname == "/privacy"} href="/privacy">
Privacy Policy
</Navbar.Link>
</Navbar.Collapse >
I'm expecting the navbar to collapse. I use the Link from next/link because Next.js downloads those links in the background and do optimizations.
I also tried
const [open, setOpen] = useState(false);
<Navbar.Link as={Link} onClick={() => setOpen(false)} active={pathname == "/privacy"} href="/privacy">
Privacy Policy
</Navbar.Link>
but it doesn't work.
Context
https://nextjs.org/docs/pages/api-reference/components/link
is a React component that extends the HTML element to provide prefetching and client-side navigation between routes. It is the primary way to navigate between routes in Next.js.
Any help appreciated 🙌
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example with next/link, Navbar.Collapse, and Navbar.Link, including the attempted menuOpen state and onClick handler. Trace how Navbar.Collapse responds to navigation and clicks, then verify that a Next.js link closes the mobile navbar while preserving client-side navigation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100