2

我有一个这样设置的路由器:

<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>

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

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

反应路由器版本是 4.2.0

4

0 回答 0