nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - DropdownItem Routing causes full refresh on NextJS

Open dl-web-dev opened this issue 2 years ago • 12 comments

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

  1. Create a dropdown component with Dropdown items setup with an href parameter
  2. Click dropdown item from dropdown menu
  3. 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

dl-web-dev avatar Dec 13 '23 17:12 dl-web-dev

Have you checked this part of the documentation? It is necessary for the link to work correctly: https://nextui.org/docs/guide/routing

torresgol10 avatar Dec 13 '23 18:12 torresgol10

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

dl-web-dev avatar Dec 13 '23 20:12 dl-web-dev

I have same problem. full refresh when dropdown item has href=""

@dml0031 you found any solution?

thallysondias avatar Dec 24 '23 19:12 thallysondias

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

dl-web-dev avatar Dec 29 '23 16:12 dl-web-dev

@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

andyryan33 avatar Feb 20 '24 21:02 andyryan33

@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!

dl-web-dev avatar Feb 21 '24 21:02 dl-web-dev

@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.

BasitAli avatar Feb 21 '24 23:02 BasitAli

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?

russx2 avatar Feb 29 '24 21:02 russx2

Second that. God bless the AI for pointing it.

Dragomir-Ivanov avatar Mar 19 '24 10:03 Dragomir-Ivanov

as={Link} worked - this should be default as soon as you add the href prop

edarioq avatar Apr 11 '24 13:04 edarioq

In my case, as={Link} worked in development but does not work in production.

iqingting avatar Apr 23 '24 06:04 iqingting

Fixed in https://github.com/nextui-org/nextui/pull/3240

wingkwong avatar Jun 15 '24 07:06 wingkwong