从 LinkContainer 中删除活动类

BRo*_*ers 0 reactjs react-bootstrap react-router-bootstrap

在我的反应应用程序中,我有用于登录和退出的按钮。注销没什么大不了的,因为它从来没有被激活过。当使用 LinkContainer(这很棒)时,它会添加一个活动类,active指示何时选择该路由。这对除buttons. 当它将`active 类添加到我的按钮时,它会在按钮后面添加一个填充的背景颜色。我不想要那个。现在是代码和图片:

按钮上的活动类

这是代码:

import { Glyphicon, Nav, NavItem, Button } from 'react-bootstrap';
import { LinkContainer } from 'react-router-bootstrap';

<Nav>
    <LinkContainer to={'/'} exact>
        <NavItem>
            <Glyphicon glyph='home' /> Home
        </NavItem>
    </LinkContainer>
    <LinkContainer to={'/documents'}>
        <NavItem>
            <Glyphicon glyph='education' /> User Documents
        </NavItem>
    </LinkContainer>
    <LinkContainer to={'/login'}>
        <NavItem>
            <Button bsStyle="primary" block>
                <span className='glyphicon glyphicon-log-in'></span>Login
            </Button>
        </NavItem>
    </LinkContainer>
</Nav>
Run Code Online (Sandbox Code Playgroud)

我希望它在我的按钮以外的所有东西上设置那个活动类。

使用react-bootstrapreact-router-bootstrap

BRo*_*ers 5

在浏览了react-router-bootstrap上的代码以及一堆不同的文章和帖子后,我明白了。

我不得不改变:

<LinkContainer to={'/login'}>
    <NavItem>
        <Button bsStyle="primary" block>
            <span className='glyphicon glyphicon-log-in'></span>Login
        </Button>
    </NavItem>
</LinkContainer>
Run Code Online (Sandbox Code Playgroud)

到:

    <LinkContainer to={'/login'} activeClassName="">
        <NavItem>
            <Button bsStyle="primary" block>
                <span className='glyphicon glyphicon-log-in'></span>Login
            </Button>
        </NavItem>
    </LinkContainer>
Run Code Online (Sandbox Code Playgroud)

使activeClassName=""工作正常,因为它可以确保没有设置活动类。

对按钮非常有帮助。我希望这可以节省人们的时间。这是比较后的样子:

没有活动类的 LinkContainer 按钮