React路由器<navlink>组件activeStyle / activeClassName无法使用浏览器历史记录

时间:2017-08-30 11:25:02

标签: javascript reactjs react-router react-redux redux-router

我的路由器设置如下:

<Provider>
    <Router history={browserHistory}>
        <BFMRoot>
            <ConnectedSwitch>
                <Route path='/' exact component={BodyWelcome} />
                <Route path='/login' component={Bodies.BodyLogin} />
                <Route path='/register' component={Bodies.BodyRegister}>
            </ConnectedSwitch>
        </BFMRoot>
    </Router>
</Provider>

我的组件如下:

<NavLink to={this.prepareRouteUrl(this.props.itemName)} activeStyle={{ backgroundColor: 'blue' }} activeClassName='active'>
    <IconLabelButton
        onPress={this.props.onSelect}
        labelText={this.props.itemName}
        fontName="FontAwesome"
        iconLeftName={this.props.itemIcon}
        hab='inline'
        fluid />
</NavLink>

单击按钮时此功能正常。导航正常,根据路径加载正确的组件。但是,当我单击浏览器后退/前进按钮时,视图和路径会正确更改,但活动类和样式保持不变。

如何使活动样式和类名与浏览器历史记录(后退/前进按钮)配合使用?

react-router版本为4.2.0

0 个答案:

没有答案
相关问题