[BUG] - DropdownItem Routing causes full refresh on NextJS
NextUI Version
2.2.9
Describe the bug
When using a dropdown as follows with NextJS app routing setup on the provider as documented:
<Dropdown>
<DropdownTrigger>
<Button>Open</Button>
</DropdownTrigger>
<DropdownMenu aria-label="Navigation">
<DropdownItem key="home" href="/home">Home</DropdownItem>
<DropdownItem key="about" href="/about">About</DropdownItem>
</DropdownMenu>
</Dropdown>
Clicking on the <DropdownItem key="home" href="/home">Home</DropdownItem> results in a full page refresh instead of a router.push as expected from the routing docs.
Searched through current issues, Discord and Discussions and did not see any issue opened yet for DropdownItem but apologies if I may have missed it!
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
- Create a dropdown component with Dropdown items setup with an
hrefparameter - Click dropdown item from dropdown menu
- Page loads with a full refresh
Expected behavior
Expect DropDownItem to navigate using nextjs router and not have a full refresh.
Screenshots or Videos
No response
Operating System Version
Browser
Browser
Chrome
Have you checked this part of the documentation? It is necessary for the link to work correctly: https://nextui.org/docs/guide/routing
Yes I have setup the app as documented. @nextui-org/link works as it should, I have only noticed this issue with DropdownItem that has the href attribute
I have same problem. full refresh when dropdown item has href=""
@dml0031 you found any solution?
I have same problem. full refresh when dropdown item has href=""
@dml0031 you found any solution?
I Have not, most likely just go back to the old method I was using and just putting a link inside of the DropdownItem
@dml0031 - if you provide as={Link} as an attribute to <DropdownItem>, it should work properly.
import Link from 'next/link';
<DropdownItem
key="about"
href="/about"
as={Link}
>
h/t @BasitAli for answering this in a different thread - https://github.com/nextui-org/nextui/issues/2301#issuecomment-1936999050
@dml0031 - if you provide
as={Link}as an attribute to<DropdownItem>, it should work properly.import Link from 'next/link'; <DropdownItem key="about" href="/about" as={Link} >h/t @BasitAli for answering this in a different thread - #2301 (comment)
Will try that as well!
However while it may fix the issue, this bug still remains as the fix goes against the routing documentation so will keep it open for now!
@dml0031 - if you provide
as={Link}as an attribute to<DropdownItem>, it should work properly.import Link from 'next/link'; <DropdownItem key="about" href="/about" as={Link} >h/t @BasitAli for answering this in a different thread - #2301 (comment)
Will try that as well!
However while it may fix the issue, this bug still remains as the fix goes against the routing documentation so will keep it open for now!
Agreed, the documentation needs fixing here.
Whilst this solution fixes the issue of using the router's navigation, it then changes the styling on how the dropdown item is rendered so isn't ideal. Surely the original issue should be considered a bug?
Second that. God bless the AI for pointing it.
as={Link} worked - this should be default as soon as you add the href prop
In my case, as={Link} worked in development but does not work in production.
Fixed in https://github.com/nextui-org/nextui/pull/3240