import { useState } from 'react';
import { Link } from 'react-router-dom'
const SideBar = () => {
const [open, setOpen] = useState(true);
const onOpen = () => {
setOpen(!open);
};
return (
<div className="main-menu menu-fixed menu-light menu-accordion menu-shadow " data-scroll-to-active="true" data-img="theme-assets/images/backgrounds/02.jpg">
<div className="navbar-header">
<ul className="nav navbar-nav flex-row">
<li className="nav-item mr-auto">
<Link to="/" className="navbar-brand" onClick={onOpen}>
<img className="brand-logo" alt="Chameleon admin logo" src="theme-assets/images/logo/logo.png"/>
<h3 className="brand-text">LaravelTricks</h3>
</Link>
</li>
</ul>
</div>
<div className="main-menu-content">
<ul className="navigation navigation-main" id="main-menu-navigation" data-menu="menu-navigation">
<li className="active"><Link to="/"><i className="ft-home"></i><span className="menu-title" data-i18n="">Dashboard</span></Link>
</li>
<li className=" nav-item"><Link to="/to-do-list"><i className="ft-pie-chart"></i><span className="menu-title" data-i18n="">Tasks</span></Link>
</li>
<li className=" nav-item"><Link to="/"><i className="la la-sign-out"></i><span className="menu-title" data-i18n="">Logout</span></Link>
</li>
</ul>
</div>
<div className="navigation-background"></div>
); }export default SideBar;
1条答案
按热度按时间z9gpfhce1#
要在单击位于侧边栏中的链接后折叠侧边栏,您需要在单击链接时调用的onOpen func中将open的状态更新为false。以下是更新后的代码: