简体   繁体   English

如何使所选项目在反应 js 的侧栏中处于活动状态?

[英]how to make the selected item active in side bar in react js?

侧边栏图像 I had hover in selecting the page, i need this as active state.我在选择页面时悬停,我需要将其作为活动状态。 I need to show active on the current page, its not working any help..?我需要在当前页面上显示 active,它没有任何帮助..? I dont want to change the text color on hover.我不想在悬停时更改文本颜色。 my sidebar.js code is :我的 sidebar.js 代码是:

<ul className="nav">

          <li className={ this.isPathActive('/dashboard') ? 'nav-item active' : 'nav-item' }>
            <Link className="nav-link" to="/dashboard">
            <Icon icon={stethoscopeIcon} />&nbsp;&nbsp;
              <span className="menu-title">Doctors</span>
            </Link>
          </li>


          <li className={ this.isPathActive('/tables') ? 'nav-item active' : 'nav-item' }>
            <Link className="nav-link" to="/tables/basic-table">
            <Icon icon={calenderIcon} />&nbsp;&nbsp;
              <span className="menu-title">Tables</span>
            </Link>
          </li>

        </ul>

By default it showing different colors on hover i need to disable all and give some color in active state.默认情况下,它在悬停时显示不同的颜色,我需要禁用所有并在活动状态下提供一些颜色。

If you are trying to apply styles for active links then you could use react-router-dom NavLink component ( https://reacttraining.com/react-router/web/api/NavLink ).如果您尝试为活动链接应用样式,则可以使用 react-router-dom NavLink 组件( https://reacttraining.com/react-router/web/api/NavLink )。

If you want to change the hover colors then you could override them using css:如果要更改悬停颜色,则可以使用 css 覆盖它们:

.nav-link:hover { ... }

For Active State, you need to use Nav Link对于 Active State,您需要使用 Nav Link

https://reacttraining.com/react-router/web/api/NavLink https://reacttraining.com/react-router/web/api/NavLink

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM