html - 如何在 React.js 中突出显示当前页面侧绘制栏选项卡
问题描述
这里我有一个侧边栏,我需要突出显示选定的选项卡
每当页面更改时,我都需要突出显示选项卡...
我怎样才能做到这一点..?
这是我的代码:
反应.js:
<Menu>
{SideBarData.map((element, i) => {
return (
<NavIcon onClick={showSidebar} to={element.path} key={i}>
{element.icon}
</NavIcon>
);
})}
</Menu>
样式.js
import { Link as LinkS } from "react-router-dom";
const Menu = styled.div`
background: ${BG_COLOR.PRIMARY_COLOR_WHITE};
display: flex;
flex-direction: column;
flex: 1;
width: 56px;
height: 100vh;
margin-left: -8px;
box-shadow: 5px 0 10px -5px #888;
position: fixed;
`;
const NavIcon = styled(LinkS)`
font-size: ${FONT_SIZE.TEXT_NORMAL};
display: flex;
justify-content: flex-start;
justify-content: center;
align-items: center;
height: 3rem;
width: 100%;
color: ${BG_COLOR.PRIMARY_COLOR_BLACK};
text-decoration: none;
border-bottom: 1px solid;
border-bottom-color: ${BG_COLOR.PRIMARY_COLOR_BLACK};
text-align: left;
&:hover {
background-color: ${BG_COLOR.PRIMARY_COLOR};
border-left: 5px solid ${BG_COLOR.PRIMARY_COLOR_BLACK};
cursor: pointer;
}
`;
在这里,我使用 styled-components 进行样式设置
解决方案
如果您的侧边栏用于更改路径,您可以从 ReactRouter NavLink尝试此功能,并使用activeClassName
.
推荐阅读
- javascript - 如何在带有条件标记渲染的传单地图中访问嵌套的 json 对象并显示标记
- android - 为什么小吃店会消失在屏幕上?
- javascript - 从 Firebase 存储和检索数据以不同的格式返回
- angular - 角度如何在组件的模板中呈现html标记
- mysql - 对于具有单词类型(名词,动词......)的语言词典,最好的方法是什么?
- c# - c#如果表处于关系中,则在getrequest中返回表数据会出错
- c++ - 使用 shared_ptr 和 unique_ptr 指向数组时的区别?
- firebase - Flutter Firebase BLoC 模式
- python - 从 CSV 文件中提取最后一行并将其放入另一个文件中,并在 Python 中使用文件名
- reactjs - 如何更改 Material-UI 表格的悬停颜色?