reactjs MUI和Next.js 13使用MenuItem和NextLink控制padding、height,因此锚与MenuItem一样宽/高

ih99xse1  于 2023-06-29  发布在  React
关注(0)|答案(1)|浏览(91)

“HTML”:

<MenuItem>
  <NextLink className={currentRoute == "/" ? "link--is-active" : ""} href={"/"}>
    HOME
  </NextLink>
</MenuItem>

嵌入的锚被MUI填充包围,当点击锚外的导航链接时,你会得到很好的mui效果,但url不会改变。如何将NextLink设置为MUI MenuItem的全宽和全高?
Image showing the padding i want on the NextLink not the MUI wrapper
我尝试将MUI元素sx prop的padding和lineHeight分别设置为0和1,但对垂直填充没有影响

fruv7luv

fruv7luv1#

反转嵌套,一切正常:

<NextLink
            className={currentRoute == '/' ? 'link--is-active' : ''}
            href={'/'}
        >
            <MenuItem>HOME</MenuItem>
        </NextLink>

相关问题