修复Nav主题移动端的菜单

This commit is contained in:
tangly1024.com
2024-11-13 14:51:28 +08:00
parent c5b6b70ee8
commit 3c2959027a
2 changed files with 83 additions and 57 deletions

View File

@@ -20,7 +20,9 @@ export const MenuItemCollapse = props => {
if (!link || !link.show) {
return null
}
// #号加标题 快速跳转到指定锚点
const isAnchor = link?.href === '#'
const url = isAnchor ? `#${link.name}` : link.href
const selected = router.pathname === link.href || router.asPath === link.href
const toggleShow = () => {
@@ -42,7 +44,7 @@ export const MenuItemCollapse = props => {
onClick={toggleShow}>
{!hasSubMenu && (
<Link
href={link?.href}
href={url}
target={link?.target}
className='py-2 w-full my-auto items-center justify-between flex '>
<div>
@@ -72,21 +74,24 @@ export const MenuItemCollapse = props => {
{hasSubMenu && (
<Collapse isOpen={isOpen} onHeightChange={props.onHeightChange}>
{link?.subMenus?.map((sLink, index) => {
// #号加标题 快速跳转到指定锚点
const sIsAnchor = sLink?.href === '#'
const sUrl = sIsAnchor ? `#${sLink.name}` : sLink.href
return (
<div
key={index}
className='
py-2 px-14 cursor-pointer hover:bg-gray-100 dark:text-gray-400 dark:hover:text-white font-bold
dark:bg-black text-left justify-start text-gray-600 bg-gray-50 bg-opacity-20 dark:hover:bg-gray-600 tracking-widest transition-all duration-200'>
{/* <Link href={sLink.href} target={link?.target}> */}
<a href={`/#${sLink.title}`} target={'_self'}>
<Link href={sUrl} target={'_self'}>
<div>
<div
className={`${sLink?.icon ? sLink?.icon : 'fas fa-hashtag'} text-center w-3 mr-2 text-xs`}
/>
{sLink.title}
</div>
</a>
</Link>
</div>
)
})}