我有一个使用reactstrap的react应用程序(bootstrap4)。我使用react-router为导航创建了一个简单的布局。我不明白为什么当你点击一个navbar项目时会闪现。我使用的是react-router-dom中的内置NavLink,它保持选中的NavItem高亮显示。
这里是网站的链接
标题组件
import {
Collapse,
Navbar,
NavbarToggler,
Nav,
NavItem,
NavbarBrand,
NavLink } from 'reactstrap'
import { NavLink as RRNavLink } from 'react-router-dom'
const Item = ({link, label}) => (
<NavItem>
<NavLink exact activeClassName='active-tab' to={link} tag={RRNavLink}>{label}</NavLink>
</NavItem>
)
const ROUTES = []
export default class extends React.Component {
render () {
return (
<div className='header-bkg'>
<Navbar color='faded' light expand='md'>
<NavbarBrand className='text-white'>Star Designs</NavbarBrand>
<NavbarToggler onClick={this._onToggle} />
<Collapse isOpen={this.state.isOpen} navbar>
<Nav className='ml-auto' navbar>
{ROUTES.map((x, i) => (
<Item key={i} {...x} />
))}
</Nav>
</Collapse>
</Navbar>
</div>
)
}
}
CSS
.header-bkg {
box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.6), inset 0 -1px 1px rgba(0, 0, 0, 0.6), 0 0 5px rgba(0, 0, 0, 0.6);
border-top: 0 solid rgba(47, 46, 46, 1);
border-bottom: 0 solid rgba(47, 46, 46, 1);
background-color: #d7a29e;
}
.nav-link:hover,
.nav-link:active {
background-color: #ede9e2;
}
.nav-link {
text-transform: uppercase;
}
.active-tab {
background-color: #ede9e2;
}
:focus {
outline: -webkit-focus-ring-color auto 0;
}
@media (max-width: 575px) {
}
@media (max-width: 767px) {
}
@media (max-width: 991px) {
}
@media (max-width: 1199px) {
}
单击菜单项时,一些js代码在折叠navbar-collable
元素上添加height:0px
(用于移动视图中关闭下拉动画效果),然后在几毫秒后将其删除。添加以下样式,它将不允许height 0
在桌面视图中应用,因为它具有更高的特异性和重要属性。因此,不会发生闪烁。
@media (min-width: 768px) {
.navbar-expand-md .navbar-collapse {
height: auto !important;
}
}